2

I am working on front-end only React application and will soon be implementing internationalization. We only need one additional language... at this point. I would like to do it in a way that is maintainable, where adding a new language would be ideally as close as possible to merely providing a new config object with translations for various strings.

The issue I know we will have, is that we have dynamic inputs inside of sentences as demonstrated below (where [] are inputs and ** is dynamically changing data). This is just an example sentence... lots of other similar type things elsewhere in the app.

I am [23] years old. I was born in [ ______▾]. In 2055 I would be *65* years old.

We could break out 'I am', '*age input', 'years old. I was born in', '*year dropdown'. etc. But depending on the language, word order could be changed or an input could be at the beginning of a sentence etc, and I feel like doing it in that way would make for a really weird looking and hard to maintain language file.

I'm looking to know if there are common patterns and/or libraries we can use to help with this challenge.

Damon
  • 10,493
  • 16
  • 86
  • 144

1 Answers1

0

A react specific library is react-intl by yahoo. Which is part of a larger project called FormatJS which has many libraries and solutions for internalization. These and their corresponding docs are a good starting point.

enjoylife
  • 3,801
  • 1
  • 24
  • 33
  • I have looked through these and didn't see anything that would help in the scenario I described. I saw date and number formatting helpers that looked quite useful, but nothing around how to handle dynamically positioning inputs within sentences – Damon Dec 23 '15 at 15:00
  • your right that it seems it is not a 1 to 1 match for your issue. Another library which you probably already looked at is [babel.pocoo](http://babel.pocoo.org/docs/messages/). Its a python library which if not a solution, at least could be a source of knowledge for how a library manipulates message catalogs. – enjoylife Dec 23 '15 at 17:34
  • Another avenue is to perhaps look at js libs which manipulate the standard file formats for message catalogs. Such as [po2json](https://github.com/mikeedwards/po2json). – enjoylife Dec 23 '15 at 17:37
  • hmm thanks I will look into those. had not run into either of them! – Damon Dec 23 '15 at 22:06