Adding sentences in .MO/PO lang files

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 ?

Comments

  • acrylian Administrator, Developer

    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:

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

  • acrylian Administrator, Developer

    Thanks, glad to hear.

  • ctdlg Member

    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"
    <?php echo gettext("Site created in 2018"); ?>

    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 !

  • acrylian Administrator, Developer
    edited December 4

    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

  • ctdlg Member

    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 !

  • acrylian Administrator, Developer

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

Sign In or Register to comment.