diff options
| author | Adrien Hopkins <[email protected]> | 2022-08-16 20:16:38 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-16 20:16:38 +0000 |
| commit | bb40e60e8623ea9a097dc5f7debe97fef94001e0 (patch) | |
| tree | a611fefe2c47468068d0d13442b5d8df009ed969 /doc | |
| parent | 6392463d4d542385bc515b07407ab462614b16bd (diff) | |
| parent | 6af45235e86686b2ea1ca54fe061e0f230a644fc (diff) | |
| download | coinos-ui-bb40e60e8623ea9a097dc5f7debe97fef94001e0.tar.gz coinos-ui-bb40e60e8623ea9a097dc5f7debe97fef94001e0.zip | |
Merge pull request #1 from coinos/i18n
Add Internationalization to CoinOS
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/i18n-technical.md | 47 | ||||
| -rw-r--r-- | doc/i18n.md | 71 | ||||
| -rw-r--r-- | doc/img/add_locale_github.png | bin | 0 -> 99036 bytes | |||
| -rw-r--r-- | doc/img/create_locale_github.png | bin | 0 -> 64118 bytes | |||
| -rw-r--r-- | doc/img/translate_github.png | bin | 0 -> 78506 bytes |
5 files changed, 118 insertions, 0 deletions
diff --git a/doc/i18n-technical.md b/doc/i18n-technical.md new file mode 100644 index 00000000..6c45ee01 --- /dev/null +++ b/doc/i18n-technical.md @@ -0,0 +1,47 @@ +# CoinOS Internationalization - Technical Information + +_NOTE: This documentation was written for people with a technical background. If you do not have a technical background, consider reading [this guide](./i18n.md) instead._ + +Last Updated: 2022-08-08 + +## Dependencies + +CoinOS's internationalization system depends on the `npm` package [`svelte-i18n`](https://www.npmjs.com/package/svelte-i18n). Consider reading [its documentation](https://github.com/kaisermann/svelte-i18n/blob/HEAD/docs/Getting%20Started.md) in addition to this. + +## Internationalization Code + +The main code for CoinOS's internationalization is at `src/lib/i18n.js`. When imported, it does the following: + +1. Load all of the locales [asynchronously](https://github.com/kaisermann/svelte-i18n/blob/main/docs/Getting%20Started.md#32-asynchronous). +2. Pick a locale intelligently, depending on the available locales and the navigator locale, using `pickLocale`. Specifically, if the user's locale (e.g. `en-US`) isn't available but its non-regional version (e.g. `en`) is, the system will use the non-regional locale. +3. Initialize `svelte-i18n`. + +It also defines important constants, including the list of available locales and the default locale. This code is loaded by importing `$lib/i18n` in `src/routes/__layout.svelte`. + +## Locale Files + +Each locale in `coinos-ui-v2` is defined by a JSON file in `src/locales`. Its name is the locale's [ISO 639-1 code](https://en.wikipedia.org/wiki/ISO_639-1) plus `.json`. It is simply a file that maps string IDs to translated strings. Here is an example of `en.json`: + +```json +{ + "howItWorks": "How It Works", + "faq": "FAQ", + "about": "About", + "startInSeconds": "Start in Seconds", + "signIn": "Sign In" +} +``` + +## Internationalizing Strings + +Strings are internationalized by simply using `svelte-i18n`'s [`$format`](https://github.com/kaisermann/svelte-i18n/blob/96a5adab7560249c8881e0612454e01c09273400/docs/Formatting.md) function. A localized string looks like this: + +``` +{$_('stringID')} +``` + +(`$_` is a convenient alias for `$format`.) + +## The Locale Selector + +CoinOS also has a `LocaleSelector` component, which should be used to select locales. It is a dropdown that allows you to select & update the locale. diff --git a/doc/i18n.md b/doc/i18n.md new file mode 100644 index 00000000..10f2995d --- /dev/null +++ b/doc/i18n.md @@ -0,0 +1,71 @@ +# CoinOS Internationalization + +CoinOS can be translated into other languages by editing JSON files. You do not need programming knowledge to do this, or to use these instructions. Here are instructions on how to internationalize CoinOS: + +_NOTE: This guide was written for people without a technical background. If you want more technical details, click [here](./i18n-technical.md)._ + +## Required Background Knowledge + +### Language Codes + +Before you can translate CoinOS, you need to know the [ISO 639-1 code](https://en.wikipedia.org/wiki/ISO_639-1) of your language. This is a standard two-letter code that your browser uses to refer to a language (for example, English is `en`, and French is `fr`). You can also add a dash and more letters to refer to a specific region (for example, American English is `en-US`, and British English is `en-GB`). A list of all codes can be found [here](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes), and Firefox-based browsers show you the code when you are selecting your browser's language. + +### Locale Files + +Each translation of CoinOS is stored in a special _locale file_. These files can be found in the `src/locales` folder in the CoinOS directory. The name of these files is the language code plus "`.json`". A file might look something like this: + +```JSON +{ + "howItWorks": "How It Works", + "faq": "FAQ", + "about": "About", + "startInSeconds": "Start in Seconds", + "signIn": "Sign In" +} +``` + +Each line (other than the opening and closing braces) contains a **text name**, then a colon (`:`), then the **translated text**. All lines other than the last end in a comma. The text name is a word that is the same in all translations, and is used by the code to access that piece of text. **Both the text name and translated text must be inside quotation marks (`"`).** + +### The Language List + +At the top of the file `src/lib/i18n.js`, there is a list of translations that looks something like this: + +```js +// The list of locales to look for +// ADD ALL NEW LANGUAGE CODES TO THIS LIST +const localeCodes = ['en', 'fr']; +``` + +In order for a translation to be recognized by the CoinOS system, you need to add it to this list. At the end of the list, before the second square bracket, add a comma, then a space, then the language code in quotation marks. + +## Creating a New Translation + +Follow these steps to create a new translation. You will need a GitHub account to do this: + +1. Determine the language code of your language, using [this list](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). For these instructions, I will be using the fictional code `xx` - replace that code with the code of whatever language you are translating to. +2. Go to the `src` folder, then the `locales` folder, then create a file `xx.json` inside that folder using either a text editor (e.g. Notepad), or GitHub. +  +3. Copy the text from `en.json` into this new file. +4. Translate all of the pieces of text on the right. **Do not translate or alter in any way the pieces of text on the left, or any line that doesn't have two pieces of text!** + _NOTE: "CoinOS" is a feminine noun in languages with grammatical gender._ +  +5. Scroll down and use the green button to commit the file. +6. Go to the `src` folder again, then `lib`, then `i18n.js`. +7. Use the pencil icon on the top-right to edit the file, then add your language code (**in quotation marks**) to the list. +  +8. Commit your changes like you did in step 5. + +## Adding to an Existing Translation + +Follow these steps to add to an existing translation. You will also need a GitHub account to do this: + +1. Determine the language code of your language, using [this list](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). For these instructions, I will be using the fictional code `xx` - replace that code with the code of whatever language you are translating to. +2. Go to the `src` folder, then `locales`, then `en.json`. +3. Find the line with the piece of text that you want to translate. +4. Find your translation's file, at `src/locales/xx.json`. +5. Use the pencil icon on the top-right to edit the file. +6. Add the whole line (both left and right parts) from step 3 to this file, in between the `{}` braces. Make sure the previous line has a comma at the end. +7. Translate the piece of text on the right, keeping the quotes surrounding it. **Do not translate or alter in any way the piece of text on the left, or any line that doesn't have two pieces of text!** + _NOTE: "CoinOS" is a feminine noun in languages with grammatical gender._ +8. Repeat steps 3-7 for every piece of text you want to translate (you should probably open `en.json` in another tab, so that your changes from step 6 aren't erased). +9. Scroll down and use the green button to commit the file. diff --git a/doc/img/add_locale_github.png b/doc/img/add_locale_github.png Binary files differnew file mode 100644 index 00000000..1a75b223 --- /dev/null +++ b/doc/img/add_locale_github.png diff --git a/doc/img/create_locale_github.png b/doc/img/create_locale_github.png Binary files differnew file mode 100644 index 00000000..538124da --- /dev/null +++ b/doc/img/create_locale_github.png diff --git a/doc/img/translate_github.png b/doc/img/translate_github.png Binary files differnew file mode 100644 index 00000000..22e33174 --- /dev/null +++ b/doc/img/translate_github.png |
