Fork me on GitHub

How be gettext ready?  Bottom

  • Hi,

    I was wondering how i would go about making a module gettext ready/enabled. I was browsing the Cozi, and for example, I noticed drak has create a News module that is gettext enabled. How would a developer ensure their module is gettext enabled?

    thanks,

    supa

    --
    ttgapers.com - the latest from the caribbean
    Caribbean News
    Online Shopping from USA, Canada, UK, France, Germany
    On Facebook
  • There are some docs in the wiki: direct link

    basically, you need to convert all your language defines to gettext strings with the appropriate function employed. There are different ways in templates vs. PHP.

    drak has a script that he can run on your module. if you ask him, he may do so, but it isn't infallible. You need to review everything afterwards.

    you can also look at some modules that are already converted to get an idea how it should work. One reference is the newest version of PostCalendar which I converted (with a lot of Drak's help), and is now Zikula 1.2 only (gettexted with no backward-compatibility).
  • Hmm....just quickly skimmed it thus far, and thanks for the pointers. What if I have a multi-language module? What would you set the $domain var to be?

    Might have to contact drak. Might be time to make the PNAmazon module public.

    supa

    --
    ttgapers.com - the latest from the caribbean
    Caribbean News
    Online Shopping from USA, Canada, UK, France, Germany
    On Facebook
  • For a multi language module, you would just have multiple translations. In fact, all modules are now multi-language icon_smile That's how it is designed.

    The $domain is just set to your mod name. It isn't language-specific

    Code

    $dom = ZLanguage::getModuleDomain('PNAmazon');


    then later, the translation portal takes hold of the .pot file you create and you can have it translated to any language there. take a look at PostCalendar in the portal: [link]

    I know drak is planning to get a bunch more information out about all the gettext stuff as soon as 1.2 is released.

    It would be great to have your module public!
  • I understand with gettext we now just type our text directly into our functions. What is the standard for making sure you use the same wording for things you want to be the same. i.e. File not found. Before I knew I could use the define _FILENOTFOUND and was sure I would get the same string, what prevents me now from having different wordings for the same thing?
  • The best way I've found so far is to work with an IDE like Eclipse, which lets you easiy browse code in a big codebase, and lets you do search/replace in multiples files. Plus, the norm now is for each module to have one, single .pot file, so all your strings are in one file. But it's true that the onus is mainly on you, so I guess one just has to as be attentive to your strings as you would be to your templates and CSS...

    Quote

    I understand with gettext we now just type our text directly into our functions. What is the standard for making sure you use the same wording for things you want to be the same. i.e. File not found. Before I knew I could use the define _FILENOTFOUND and was sure I would get the same string, what prevents me now from having different wordings for the same thing?
  • @mjturn:
    I guess that you mean to reuse strings like 'Edit', 'Delete', 'File not found' ?
    If so, I thought the same, but gettext comes with a new paradigm:

    The modularity goes to the translations too, each extension with it's own translation catalog and that's why reuse of other strings is not recommended. I was reluctant at the beginning, I wanted to reuse the 'Edit', 'Meta data', and all those common and widely used strings; I had some discussions with the core-devs about it and I realized the easiness of maintain each translation separated.

    So, the core will be not attached to any string because it's used by third party devs, nor conflicts with its translations because a string can be used in different contexts... and even technically:

    We have a Bash script to convert the pnML functions and plugin calls to gt, as the first step of the conversion. And a second one to extract the catalog (POT file). That one, parses the extension code, and give you the catalog with all the strings, it can't discard the ones that you used from another gettext domain... so, better to have them separated from many points of view, and to translate those few common words with poEdit is not hard at all icon_wink

    Greetz

    --
    - Mateo T. -
    Mis principios... son mis fines
  • The main reason for not sharing msgid's is simple - unlike defines which were just mnemonics, gettext strings are real sentences... all it takes is for someone to tweak and suddenly ALL 3rd party modules would break. It's a totally different paradigm.

    Gettext is meant to be used with Translation Memory: this means as you translate (or indeed as others translate) you can store the translations. When you begin a new PO file you run the auto translate on it and bang, all the repetitive key are translated.

    Regards,

    Drak

    --
    Zikula Lead Developer
    Board Member of the Zikula Foundation
    Follow me on twitter.com/zikuladrak
  • Thanks for the explanation (Mateo & Drak)!

    I didn't want to miss something if there was a new way to define common terms, but that does make sense it is just hard to get my head around.
  • Another question. How do we do language overrides. Currently I am putting them in my theme/lang directory. I have a client that likes to change the wording of things in the core... will I still be able to do that? And how?
  • /config

    ref: Template Overriding
  • Code

    /config/locale/$lang/LC_MESSAGES/$domain.mo
    So, if you want to customize the Profile translations for Spanish ($lang = es), you take the PO file from /modules/Profile/locale/es/LC_MESSAGES/module_profile.po, customize it with poEdit, and upload it to: /config/locale/es/LC_MESSAGES/module_profile.mo

    Even easier to customize than before, and customers can use poEdit with no problems I guess icon_razz

    --
    - Mateo T. -
    Mis principios... son mis fines
  • Thanks Mateo!!

This list is based on users active over the last 60 minutes.