1.0.17 • Published 4 years ago

@secret-escapes/i18n v1.0.17

Weekly downloads
50
License
Apache License 2....
Repository
-
Last release
4 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

4 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago