1.0.17 • Published 3 years ago

@secret-escapes/i18n v1.0.17

Weekly downloads
50
License
Apache License 2....
Repository
-
Last release
3 years ago

Secret Escapes i18n Library

Description

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

Examples

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

<Translation
        translationKey={'a.key.with.two.choices.and.one.argument'}
        translationArguments={[1, 5, 'London']}
        translationObject={jsonObject}
      />

1 adult and 5 children from London

<Translation
        translationKey={'a.key.with.no.arguments'}
        translationObject={jsonObject}
      />

This is a translation with no arguments.

1.0.17

3 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago