Contexts proposal
See original GitHub issueOne of the main feature request from other people, who sees c-3po
is the context
feature.
Context allows us to translate the same word (the same msgid) differently, depending on the context.
For C, C++ there are separate functions for applying context to the translation: pgettext, npgettext (for single and plural forms accordingly)
pgettext(<context>, <msgid>);
pngettext(<context>, <single form>, <plural form>, <count>);
As for me I don’t like the idea of having separate functions for that. As it was designed for C initially, they almost had no other option. But we can make it better, so I would like to implement succinct API for the c-3po
.
Proposal 1
To introduce special c
function, that will return an object with all c-3po functions with applied context. It will accept context value as a first argument.
import { c, t } from 'c-3po'
c('context').t`Hello ${ user.name }`
// maybe better to place it on a separate lines
c('context')
.t`Hello ${ user.name}`
import { ngettext, msgid, c } from 'c-3po'
c('context').ngettext(msgid`${ n } banana`, `${ n } bananas`, n);
One thing that I am worried about, is that syntax becomes a little bit overloaded. But in general, I think context is not so frequent case. And with this apporach, it is clear how to introduce some other concepts like domains
by just chaining them one after another.
d('domain')
.c('context')
.t`translate me`
Proposal 2
Place context information right into the t
function call;
import { t } from 'c-3po'
t('context')`Hello ${ user.name}`
import { ngettext, msgid } from 'c-3po'
ngettext('context')(msgid`${ n } banana`, `${ n } bananas`, n);
This one looks a little bit cleaner that Proposal 1, but the question is how do we extend this to have domain info? Maybe something like this will work:
t({context: 'context', domain: 'domain'})`Hello ${ user.name}`
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (6 by maintainers)
available in
0.7.0
version. doc - https://c-3po.js.org/contexts.htmlready in
0.7.0-release
branch. Will be available soon in0.7.0-beta
, stay tuned 😄