I've been trying to find more interesting ways to ...
# thinking-together
i
I've been trying to find more interesting ways to handle localization -- what we're currently doing is using graphql to query for each bit of text -- Has anyone written on how you'd do it in a pure language? Also if anyone's written something more holistic that combines "localized text" and "localized prices" / marketing text and db models I'd be interested. So far everything seems to get about this far:
var greeting = i18n.__('Hello');
and stops there as localization is "solved" 😛
😢 1
g
I'm guessing you've read this but the example you posted suggests maybe not so posting https://metacpan.org/pod/Locale::Maketext::TPJ13
🍰 1
👀 1
Also I don't have a suggestion really except that
var greeting = i18n.__('Hello');
sets off warning signals to me as it seems to suggest that 'Hello' will translate the same eveywhere it's used. That's not my experience so I'd expect
var greeting = i18n.__(I81N_GREETING_ID_24);
given that some other place in the code will may also need 'Hello' but it will be a different 'Hello'
c
i18n.__('Hello')
suggests to me that the strategy here is the "`gettext`" way in which the translations are extracted from the codebase then replaced in runtime, and key of a translation is a original string in the
en
version of it.
It sounds weird to me that you are
using graphql to query for each bit of text
. You should have files that consolidate all translations for a locale for your app/system and then fetch them all at once (the most appropriate translations file), depending on the user's locale.
i
ah yeah,
i18n.__('Hello')
was just a reference to the
gettext
approach, which I've run into most frequently. I'm looking for more interesting approaches. the full approach we're using is Contentful -> Graphql query to get all our text -> it's loaded into the cache -> react hooks that query the graphql cache at the component level to get specific text, looks kind of like
const text = useText('section.heading.hello')