dynamic translation with I18Next and Aurelia

Neglected Sanity

I have an aurelia app that I am integrating I18Next with, I have the Aurelia integration working and it was all going smoothly, until I came upon our menu. For normal translations we are just using the html attributes like so...

<a href="somelink" i18n="link1">Link 1</a>

then in translation.json files you have

{
  link1: "some translation here"
}

and that works great, it translates perfectly. The problem I can't figure out is how to handle dynamic stuff, like for example our menu. We are doing a repeat.for to make the menu, but how do I tell I18Next what key to use from the translations.json file? Here is a simplified example of what I mean.

<li repeat.for="item of router.navigation">
  <a href.bind="item.href" class="${item.isActive? 'is_active' : ''}>
    ${item.title}
  </a>
</li>

Given the above layout, how can you possibly tell I18Next what keys to use for translation, since it is done in a loop. I have tried a few things, but all have failed. I am really stuck here, I need to get this to translate using the translation.json files, but I have no idea how to tell it what key to use for the translation, is it "home", "about", "contact", ...? Any help would be really appreciated. Thank you.

Jesse

Just like any other attribute, you can bind to your i18n attribute with aurelia. Using the following syntax:

<a i18n.bind="'navigation.' + item.title"></a>

I18n will look for a key in your resources file with the name navigation.[item.title], so if the item.title variable equals to "home", it will look for a key named navigation.home.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

HTML tags in i18next translation

Jquery i18next translation issue

i18next translation outside component

i18next return translation of all languages as object

i18next translation being displayed as unicode hex character

i18next dealing with multiple translation files nested namespaces

i18next import translation from database

i18next with namespace does not fetch expected translation file

Update translation without page refresh (i18next with react)

i18next appends the default translation namespace to my namespaces

Ternary expression translation with i18next react js

using multiple translation files in aurelia i18N

React Typescript i18n : i18next::translator: missingKey en translation

How to add routes in a React/Gatsby app when I use i18next to handle translation?

Localization of static HTML with i18next (loading local json translation files)

React i18next fails to load translation.json as json from django

I18Next does not find translation for languages be-fr and be-nl

How can I translate dynamic sentence with react i18next?

Translation For Dynamic Data Using Rails I18n

How to make meta tags dynamic depending on the language on the site in React APP? [React Helmet + i18next]

React i18next loading translation files both from frontend (e.g. localhost :3000) and backend (e.g. localhost:5000)

Dynamic translation of combobox qml

react-i18Next: Using an enum for translation key values

Aurelia, webpack and dynamic reference to images

Dynamic radio/checkbox solution in Aurelia

Add translation on server side only using next-i18next

i18next changing resGetPath on the fly

i18next react - HTML tags

Iterating over array in i18next