Gettext: Is it a good idea for the message ID to be the english text?

后端 未结 11 1372
春和景丽
春和景丽 2020-12-07 16:45

We\'re getting ready to translate our PHP website into various languages, and the gettext support in PHP looks like the way to go.

All the tutorials I see recommend

11条回答
  •  旧时难觅i
    2020-12-07 17:30

    At the end of the day, a translator should be able to sit down and change the texts for every language (so they match in meaning) without having to involve the programmer that already did his/her job.

    This makes me feel like the proper answer is to use a modified version of gettext where you put strings like this

    _(id, backup_text, context)
    
    _('ABOUT_ME', 'About Me', 'HOMEPAGE')
    

    context being optional

    why like this? because you need to identify text in the system using unique ID's not english text that could get repeated elsewhere.

    You should also keep the backup, id and context in the same place in your code to reduce discrepancies.

    The id's also have to be readable, which brings in the problem of synonyms and duplicate use (even as ids), we could prefix the ids like this "HOMEPAGE_ABOUT_ME" or "MAIL_LETTER", but

    1. people forget to do this at the start and changing it later is a problem
    2. its more flexible for the system to be able to group both by id and context

    which is why I also added the context variable at the end

    the backup text can be pretty much anything, could even be "[ABOUT_ME@HOMEPAGE text failed to load, please contact example@example.com]"

    It won't work with the current gettext editing programs like "poedit", but I think you can define custom variable names for translations like just "t()" without the underscore at the start.

    I know that gettext also has support for contexts, but its not very well documented or widely used.

    P.S. I'm not sure about the best variable order to enforce good and extendable code so suggestions are welcome.

提交回复
热议问题