i18n system used internally at Secret Escapes

Usage no npm install needed!

<script type="module">
  import secretEscapesI18n from 'https://cdn.skypack.dev/@secret-escapes/i18n';


Secret Escapes i18n Library


This library contains two parts.

  • An i18n function which takes an object of key value pairs. They key is an identifier and the value is a translation. This has been tested on a Phraseapp output but this should work with most standard internationalisation library outputs

  • A react component which takes parameters and calls the library to output the translated text


Given the following json object:

const jsonObject =
   "a.key.with.no.arguments":"This is a translation with no arguments.",
   "a.key.with.one.choice":"{0} {0,choice,1#Child|1<Children}",
   "a.key.with.two.choices.and.one.argument":"{0} {0,choice,1#adult|1<adults} and {1} {1,choice,1#child|1<children} from {2}"

i18n('a.key.with.no.arguments', [], jsonObject)

This is a translation with no arguments.

i18n('a.key.with.one.choice', [1], jsonObject)

should return 1 Child

i18n('a.key.with.one.choice', [2], jsonObject)

2 Children

i18n('a.key.with.two.choices.and.one.argument', [1, 5, 'London'], jsonObject)

1 adult and 5 children from London

The react component calls the library in the same way except the arguments are optional if they would be empty

        translationArguments={[1, 5, 'London']}

1 adult and 5 children from London


This is a translation with no arguments.