PatRoy Posted March 27, 2020 Share Posted March 27, 2020 (edited) Hello folks, So, trying to create a multilingual website using gettext. Now, just the simplest examples doesn't seem to work for me. I've loaded gettext.so in my php.ini (see http://corbeauperdu.ddns.net/phpinfo.php) and created a PO / MO pair with POEdit. My MO/PO file reads: msgid "" msgstr "" "Project-Id-Version: Prestadesk\n" "POT-Creation-Date: 2020-03-26 21:08+0100\n" "PO-Revision-Date: 2020-03-27 07:59+0100\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Poedit 2.3\n" "X-Poedit-Basepath: ../../../..\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" "X-Poedit-SourceCharset: UTF-8\n" "Last-Translator: \n" "Language: fr\n" "X-Poedit-SearchPath-0: .\n" #: templates/prestadesk_dashboard.php:41 #, php-format msgid "Welcome, %s!" msgstr "Bienvenu, %s!" #: templates/prestadesk_dashboard.php:42 msgid "This page will show the dashboard" msgstr "Cette page affichera le tableau de bord" It's located under <DOC_ROOT>/prestadesk/include/locales/fr/LC_MESSAGES/prestadesk.po And I've got this very simple php test page under <DOC_ROOT>/prestadesk/templates/prestadesk_dashboard.php <?php $lang='fr'; $domain = 'prestadesk'; $codeset = 'UTF-8'; $locales_dir = '../include/locales'; // need to go up on directory from here to get into the include/locales // here we define the global system locale given the found language putenv('LANG='.$lang); // this might be useful for date functions (LC_TIME) or money formatting (LC_MONETARY), for instance setlocale(LC_ALL, $lang); // this will make Gettext look for $locales_dir/<lang>/LC_MESSAGES/prestadesk.mo bindtextdomain($domain, $locales_dir); // indicates in what encoding the file should be read bind_textdomain_codeset($domain, $codeset); // here we indicate the default domain the gettext() calls will respond to textdomain($domain); // test translate echo gettext("This page will show the dashboard"); ?> Nothing happens. No translation, no errors... I just see the message in English Any ideas for me ? Thanks a bunch! Edited March 27, 2020 by PatRoy Quote Link to comment Share on other sites More sharing options...
PatRoy Posted March 28, 2020 Author Share Posted March 28, 2020 Found the solution by putting website on another server : turns out I need to install my desired website locales (fr_FR, nl_NL) on my server with locale-gen. Works on an ArchLinux box, but tool doesn't exist on my real server (a NAS). I have a 'localedef' on my NAS to help generate locales, but my NAS is missing all requirements for this it seems under /usr/share/i18n/ ... I'm lost here... Any advice on an alternative to gettext ? Quote Link to comment Share on other sites More sharing options...
gizmola Posted March 28, 2020 Share Posted March 28, 2020 What distro is the NAS server based on? Do you have a package management tool you can use to add/update packages? Quote Link to comment Share on other sites More sharing options...
PatRoy Posted March 29, 2020 Author Share Posted March 29, 2020 (edited) It's a fairly old NAS... (DLink DNS325). I've installed Fonz Fun_plug (ffp) 0.7 on it a while back now: https://nas-tweaks.net/398/installing-and-uninstalling-packages-in-fonz-fun_plug-0-7/ uname reads: Linux datahub 2.6.31.8 #8 Tue Jun 26 11:38:41 CST 2012 armv5tel GNU/Linux I do have a package manager from the FFP installation named 'slacker' or 'funpkg'... but can't see anything in there in regards of locale* ... In short, ffp installs to /ffp. Apps, base system of it simply chroots into /ffp/... I do have 'locale' and 'localedef' on the main NAS OS in /usr/sbin/locale*, but no charmaps, to create the locales with that localedef. Tried copying the files from my ArchLinux install /usr/share/i18n/* and symlink them on my NAS in /usr/share/i18n/: ln -s /ffp/usr/share/i18n/ /usr/share then force a creation of the locale fr_FR: localedef -v -c -i fr_FR -f UTF-8 fr_FR.UTF-8 but for one thing, I'm getting a bunch of warnings such as: Quote /usr/share/i18n/locales/fr_FR:168: non-symbolic character value should not be used and finally, at the end get a : Quote cannot open locale archive "/usr/lib/locale/locale-archive": Read-only file system Info on this locale-archive: root@datahub:~# ll /usr/lib/locale/locale-archive lrwxrwxrwx 1 root root 44 Mar 28 23:18 /usr/lib/locale/locale-archive -> /usr/local/modules/web/config/locale-archive root@datahub:~# mount | grep /usr/local/modules /usr/local/tmp/image.cfs on /usr/local/modules type squashfs (rw,loop=/dev/loop0) Even though it says 'rw' in my mount options, I can't write to that FS... That's pretty much all the info I've got and tried p.s.: if I cant do anything with gettext, any way I could temporarily use something like XMLs, JSONs etc? I was thinking of writing a Locale class that would accept a boolean say "useGettext" in the constructor... If it's set, then simply return gettext's value when calling Locale::myGettext("Some string"); if it's NOT set, then my Locale::myGettext would fetch data in an XML /JSON or what ever else approach... All my code in my pages would use something like: Locale::myGettext("Some string"); Locale::mynGettext("You have one mail", "You have %d" mails", $totalMail); Is this approach stupid ? I would prefer just using gettext()... Thanks again for your help Edited March 29, 2020 by PatRoy Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.