DEV Community

Cover image for i18n management made easy
Tails128
Tails128

Posted on

i18n management made easy

"How do we handle the localization? Do we have a repo, do we use any service? Do I need to contact someone?"

"We have a json which we edit"

Did this ever happen to you? If it did, I may have the solution for you!

I've recently stumbled upon the classical "we kinda have localization but we kinda don't" issue and I've decided to make a micro-library so that -at least- we can collaborate on Google Sheets. Give it a look!

It's very simple to use (if you think it's not please give me a feedback and I'll do my best to make it more intuitive!) and it basically just requires your API keys or your service account in case you're working within a company.

Configuring the Google Sheets doc
Pretty straightforward:

first row:

  • The first cell is 'locaKeys', which will just hold the translation keys
  • The other cells contain the localization name (en-uk, de-de, etc...)

other rows:

  • the first cell contains the key for the translation: univoque and i suggest no spaces and all uppercase, to make it easy to spot if there's somthing wrong with the translations.
  • the other cells contain the value for the corresponding language

here's an example:
Image description

Use it freely via:

npm i -D loca-mapper

Top comments (2)

Collapse
 
anastawfik profile image
Anas Tawfik

lovely idea, have you considered other cases like variables or trnslations based on a count?

Collapse
 
tails128 profile image
Tails128

@anastawfeek Yup!

Usually in that case what I do is to place a placeholder (e.g.: {{n}}) and replace via code! This would have to be duplicated in every language as it may of course lie in different points of the sentence, eg:

  • IT: "Oggi Γ¨ il {{0}} giorno senza incidenti!" (4th word)
  • EN: "Today's the {{0}} day without accidents" (3rd word)

The reason for the number is that in cases like these you may want to mass replace a certain subject:

"My {{0}} is painted {{1}} because the color {{1}} is cool! Oh and my {{0}} is also cool!"

So what you may want is to have an helper function in which you pass your replacements, .foreach them and apply the translation via .replaceAll!

The reason I did not include such system in the library is that this aims to be just a document-to-ts (or js) transpiler, as for the execution I prefer to let the user use the i18n library they prefer!