I am currently using i18n to translate strings and I'm looking for a way to attach a variable onto the path.
This variable could be about 8 different values and each need a different translation. My locale files already include the translations but I don't know how to add my variable onto the translation path. I don't think variable interpolation helps me here.
content.state //variable
t ('.state') //locale path
I'm looking for a way to add the content.state variable to the end of the locale path so that it translates depending on what content.state is. Currently my only solution is a large if/else covering all the states.
Solved: I was trying to find a way to add a variable to the locale path inside handlebars and ended up using the concat helper.
{{ t (concat "state." content.state)}}
Internationalization (or i18n) is the process of marking strings for translation, so that the strings can be extracted from the source code and given to translators. Localization (l10n) is the process of translating the marked strings into different languages.
Internationalization (sometimes shortened to "I18N , meaning "I - eighteen letters -N") is the process of planning and implementing products and services so that they can easily be adapted to specific local languages and cultures, a process called localization .
You can do that like this (example):
I18n.t('helpers.links.add', variable: "Your Variable Value")
then, on your translation file (yml):
helpers:
links:
add: "Add %{variable}"
That way, in my example, the output would be: Add Your Variable Value.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With