ZenphotoCMS Forum
Adding sentences in .MO/PO lang files - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: Adding sentences in .MO/PO lang files (/thread-14005.html)



Adding sentences in .MO/PO lang files - ctdlg - 2024-11-29

Hello,
Can we define our own sentences in lang dictionaries.
As an update will erase Mo and Po files (zp-core/locale folder), can we create our own lang dictionaries in another folder ?




Adding sentences in .MO/PO lang files - acrylian - 2024-11-29

That is currently not possible for the core. itself. But if you use a custom theme it can have its own translation as can custom plugins.

Please see:




Adding sentences in .MO/PO lang files - ctdlg - 2024-11-29

The more I use Zenphoto, the more I find it fantastic !
I will add what I need to my theme, following your tutorials.




Adding sentences in .MO/PO lang files - acrylian - 2024-12-01

Thanks, glad to hear.




Adding sentences in .MO/PO lang files - ctdlg - 2024-12-04

I cannot load my translation file.

What I did : a file
/theme/mytheme/traductions.php
This file contains only words and sentences to translate.
These words and sentences are used in my album.php and image.php files.
My code to display - example, based on "next"

Then, using my terminal, I created a pot file :
xgettext --language=PHP --from-code=UTF-8 --output=traductions.pot traductions.php

Then, I opened this pot file using Poedit, translated my sentences, added version and author, compiled the MO
it is located in
/themes/mytheme/traductions/locale/fr_FR/LC_MESSAGES/

Po file contains lines like
msgid "Site created in 2018"
msgstr "Site créé en 2018"

I tried adding my translations in index.php, but without success :
bindtextdomain('/themes/mytheme/traductions', DIR . '/locale');
echo gettext("next") . "
";
echo dgettext("traductions", "Site created in 2018") . "
";

next is translated (Zenphoto translation), but not Site created (My translation.)
Textdomain is Zenphoto.

It is not clear for me how and where to add my own theme translations !




Adding sentences in .MO/PO lang files - acrylian - 2024-12-04

The location is wrong with /themes/mytheme/traductions/locale/fr_FR/LC_MESSAGES/.

It must be /themes/mytheme/locale/(…) and you also need to use the proper translating gettext_th() functions as also documented: https://www.zenphoto.org/news/translating-tutorial/#--theme-translations. A file like /theme/mytheme/traductions.php is not necessary, strings are used where they are used and parsed by Poedit for the catalogue.

https://docs.zenphoto.org/1.6.5/namespaces/default.html#function_gettext_th




Adding sentences in .MO/PO lang files - ctdlg - 2024-12-04

Thank you, acrylian.

My path was bad, and I used
gettext instead of gettext_th !
Now, it works (without adding bindtextdomain('/themes/mytheme/traductions', DIR . '/locale'); at the top of index.php)

It is more simple than what I thought !




Adding sentences in .MO/PO lang files - acrylian - 2024-12-04

Great, we tried to make that as simple as possible.