Add Internationalization I18n Locale

Adding /usr/lib/locale dir allows mounting /mnt/flash or even tmpfs to build locale files

`Author: Gregory Hinton Nietsky gregnietsky@gmail.com
Date: Fri May 17 15:39:36 2019 +0200

Add Locale support

diff --git a/common/classes/swi-image-minimal.bbclass b/common/classes/swi-image-minimal.bbclass
index 50ef1c3…b1a1875 100644
— a/common/classes/swi-image-minimal.bbclass
+++ b/common/classes/swi-image-minimal.bbclass
@@ -59,4 +59,9 @@ fakeroot do_label_files() {
fi
}

-IMAGE_PREPROCESS_COMMAND_append = " do_rm_unused_files; do_label_files; "
+# Make locale mount point
+do_create_locale() {

  • mkdir -p ${IMAGE_ROOTFS}/usr/lib/locale
    +}

+IMAGE_PREPROCESS_COMMAND_append = " do_create_locale; do_rm_unused_files; do_label_files; "
``

The def files are added to the rootfs to be compiled on demand

diff --git a/meta-swi-mdm9x28/recipes-core/images/mdm9x28-image.inc b/meta-swi-mdm9x28/recipes-core/images/mdm9x28-image.inc

index 454377b…402d8ca 100644
— a/meta-swi-mdm9x28/recipes-core/images/mdm9x28-image.inc
+++ b/meta-swi-mdm9x28/recipes-core/images/mdm9x28-image.inc
@@ -70,6 +70,43 @@ IMAGE_INSTALL_append = " tzdata-misc"
IMAGE_INSTALL_append += “linphone-c”
IMAGE_INSTALL_append += “linphone-ring”

+# Add locale
+IMAGE_INSTALL_append += " glibc-utils"
+IMAGE_INSTALL_append += " localedef"
+
+# ZA
+IMAGE_INSTALL_append += " glibc-localedata-af-za"
+IMAGE_INSTALL_append += " glibc-localedata-en-za"
+IMAGE_INSTALL_append += " glibc-localedata-nr-za"
+IMAGE_INSTALL_append += " glibc-localedata-nso-za"
+IMAGE_INSTALL_append += " glibc-localedata-ss-za"
+IMAGE_INSTALL_append += " glibc-localedata-st-za"
+IMAGE_INSTALL_append += " glibc-localedata-tn-za"
+IMAGE_INSTALL_append += " glibc-localedata-ts-za"
+IMAGE_INSTALL_append += " glibc-localedata-ve-za"
+IMAGE_INSTALL_append += " glibc-localedata-xh-za"
+IMAGE_INSTALL_append += " glibc-localedata-zu-za"
+
+# es
+IMAGE_INSTALL_append += " glibc-localedata-es-es"
+
+# fr
+IMAGE_INSTALL_append += " glibc-localedata-fr-fr"
+
+# de
+IMAGE_INSTALL_append += " glibc-localedata-de-de"
+
+# it
+IMAGE_INSTALL_append += " glibc-localedata-it-it"
+
+# pt
+IMAGE_INSTALL_append += " glibc-localedata-pt-pt"
+
+#charmap
+IMAGE_INSTALL_append += " glibc-charmap-ansi-x3.4-1968"
+IMAGE_INSTALL_append += " glibc-charmap-utf-8"
+IMAGE_INSTALL_append += " glibc-charmap-iso-8859-1"
+

Simple script to create the locale

#!/bin/sh

setup_locale() {
        if [ ! -d /usr/lib/locale/${1}.UTF-8 ] && [ -e /usr/share/i18n/locales/${1} ];then
                if ! localedef --no-archive -f UTF-8 -i ${1} /mnt/flash/locale/${1}.UTF-8;then
                        exit 1;
                fi;

        fi;
        if [ ! -e /usr/lib/locale/.${1}.UTF-8 ] && [ -d /mnt/flash/locale/${1}.UTF-8 ];then
                if localedef --add-to-archive /mnt/flash/locale/${1}.UTF-8;then
                        touch /mnt/flash/locale/.${1}.UTF-8
                else
                        exit 1
                fi;
        fi;
}

setup_locale_dir() {
        if [ -e /usr/lib/locale/locale-archive ];then
                return 0
        fi;

        if [ ! -d /mnt/flash/locale ];then
                mkdir /mnt/flash/locale
        fi;

        if [ -d /usr/lib/locale ];then
                mount --bind /mnt/flash/locale /usr/lib/locale
        else
                exit 1;
        fi;
}

setup_locale_all() {
        setup_locale_dir

        for locale in af_ZA de_DE en_GB en_US en_ZA es_ES fr_FR it_IT nr_ZA nso_ZA pt_PT ss_ZA st_ZA tn_ZA ts_ZA ve_ZA xh_ZA zu_ZA;do
                setup_locale ${locale}.UTF-8

        done;
}

if [ "${1}" ];then
        setup_locale_dir
        setup_locale ${1}
else
        setup_locale_all
fi;