feat: Add context-aware gettext functions - #35
Conversation
|
@HB9HIL Thanks for this! I have a few follow-ups: Could you try running It would be good to validate the domain used in these new methods, similar to what we already do in You added a nice explanation of the new methods in the PR description - could we also include that in the README? At the moment, only one of the new functions is documented there. |
|
Hello @michalsn Thx for the nice feedback! I fixed the things you mentiond
😄 |
|
PS: I played a bit around with tests for the context-aware functions. But I'm not 100% how to achive that. Due to the nature of gettext it could be hard to setup a working test environment. One solution could be to make those functions in a dedicated namespace available as stub functions which could work pretty good. But I don't have that much experience with that and it's more trial and error than something I can add to this PR in good conscience. |
|
That's fine. Thanks! |
Context-aware gettext functions are not part of the default php-gettext extension. So wouldn't it be nice if this Gettext Class for Codeigniter 4 supports those aswell?
This PR implements the gettext context functions and are used the following way:
Four context-aware gettext functions have been added to handle translations where the same string may have different meanings depending on context:
pgettext()- Context-aware gettextnpgettext()- Context-aware plural gettextdpgettext()- Context-aware gettext with domaindnpgettext()- Context-aware plural gettext with domainUsage Examples
pgettext($context, $message)Translates a message within a specific context.
npgettext($context, $singular, $plural, $count)Handles plural forms with context.
dpgettext($domain, $context, $message)Translates with both domain and context.
dnpgettext($domain, $context, $singular, $plural, $count)Combines domain, context, and plural handling.
Why use context?
Context prevents translation conflicts when the same word has different meanings:
Checklist: