Skip to content

Commit

Permalink
refactor: relocate i18n files (#706)
Browse files Browse the repository at this point in the history
delete now empty misc directory
  • Loading branch information
FI00ds authored Nov 11, 2024
1 parent c962213 commit 285d54c
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 195 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ backend/cdk.out/
backend/infra.js

# game data files
misc/i18n/*.json
src/lib/i18n/*.json
85 changes: 85 additions & 0 deletions docs/dev/i18n.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# I18n

If you come across any issues with the translation setup, just send a message
in [dev-chat](https://discord.com/channels/800607517074784256/1198367043167195246) on the discord server

### Adding a new language

When adding a new language

- create a new locale file in `public/locales` if the appropriate one does not yet exist.
- in `src/lib/i18n/generateTranslations.ts`, modify the `outputLocaleMapping` as necessary so that future gameData
updates are also applied to the newly created locale, and then copy + paste the relevant `gameData.yaml` file into
the newly created locale folder
- in `src/lib/i18n/generateTranslations.ts`, modify `tbNames` to set the proper name for Stelle/Caelus for your locale if
it is not already done.
- add the new language to the list of languages in `src/lib/i18n/i18n.ts` if it does not already exist, and add a flag in
`public/assets/misc/flags`, with the name `[locale].webp`. (all current flags are downloaded
from https://flagpedia.net)
- once the translation has been completed, add the language to the list of completed languages in
`src/lib/i18n/LanguageSelector.tsx`.

### Adding new text

When any displayed text is added to the webpage, it should be done directly through the i18n setup.

- Add the new translation strings in the relevant en yaml file
- if a new file is necessary, make sure to add it to the loaded namespaces in `src/lib/i18n/i18n.ts`
- Send a message in the discord server to notify other translators of the new text.
- Leave the en translation next to the t function in the code as a code comment
`const message = t('Thing.Messages.Success') /*'Operation successful'*/`
- **After modifying the translation files, execute `npm run update-resources` from the root directory.**

### Updating gameData.yaml

These files are generated by using the `generateTranslations.ts` file in `src/lib/i18n`.

Before running the script:

- Update, if necessary, the beta information in `src/lib/i18n/betaInformation.ts`.
- The english information must include the most recent beta information before running the script, other languages
can also have beta information added to `gameData.yaml` by making a new entry in the `betaInformation` object.
- Outdated content that is now available in game can be removed but will not cause issues if left behind.
- Add the required `.json` files (listed in `requiredFiles.md`) into the `src/lib/i18n` directory, making sure that they
are up to date with the current game version

Run the script by typing `npm run update-gameData` in the command line from the root directory.

### Writing EN yaml files

Guidelines for writing yaml files in EN:

* Keep keys unquoted
* Keep strings unquoted if possible
* If quotes are needed, use double quotes
* If double quotes would need to be escaped or if the string is excessively long, use a yaml fold `>-`
* If the string contains special characters: e.g. `{` `}` `'` `"` `:` etc, make sure they are quoted or folded

When working with code, re-use the common namespace where possible.

**After modifying the translation files, execute `npm run update-resources` from the root directory.**

### Updating other files

Updating / writing the translations for languages other than english is done via crowdin.
Reach out on [Discord](https://discord.gg/YHCCaXEhfV) if you wish to help write the translations.

You will come across some translations that look like the following:
`"valueTextPart1 $t(namespace:key, {options}) valueTextPart2"`, this is used to reference an already existing
translation within a translation string.
In most cases, such a string will be translated as follows:
`"translatedValueTextPart1 $t(namespace:key, {options}) translatedValueTextPart2"`
however there may be some cases where you find it appropriate to modify the inner section as well.

Certain strings include double braced words

You will also see some translation strings include double braced words (*Immediately draws 2 jade tile(s) and increases DMG by <u>**{{skillStackDmg}}**</u>% until the end of the current turn. This effect can stack up to 4 time(s).*).
These are used to inject a dynamic value into the translated string (e.g. a varying buff, or a number of relics, etc...).
These should be left as is in the translation, but can be moved around as needed within the sentence.

Finally, some strings will have tags in them to allow for special formatting (e.g. `codeblocks` or **bold text**).
These strings will looks something like `"<0>someText</0>SomeMoreText"`.
When translating these, the tags surrounding a section of text indicate its formatting.
However, the segments don't need to enclosed within a tag. The example above could, for example, be translated as:
`"textTranslated <0>someTextTranslated</0><1>someMoreTextTranslated</1>"`.
This would allow `someTextTranslated` to have the same formatting as `someText` all while having something else precede it in the sentence.
39 changes: 0 additions & 39 deletions misc/i18n/betaInformation.ts

This file was deleted.

25 changes: 0 additions & 25 deletions misc/i18n/requiredFiles.txt

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"predeploy": "npm run build",
"deploy": "gh-pages -d dist",
"update-resources": "npx i18next-resources-for-ts interface -i ./public/locales/en -o ./src/types/resources.d.ts",
"update-gameData": "npx tsx misc/i18n/generateTranslations.ts && npm run update-resources"
"update-gameData": "npx tsx src/lib/i18n/generateTranslations.ts && npm run update-resources"
},
"browserslist": {
"production": [
Expand Down
87 changes: 0 additions & 87 deletions public/locales/readme.md

This file was deleted.

40 changes: 40 additions & 0 deletions src/lib/i18n/betaInformation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { InputLocale } from 'lib/i18n/generateTranslations'

export const betaInformation: betaInformation = {
en: {
Characters: [
{
key: 1225,
value: {
Name: 'Fugue',
},
},
{
key: 1313,
value: {
Name: 'Sunday',
},
},
],
Lightcones: [
{
id: 23034,
value: {
Name: 'A Grounded Ascent',
},
},
{
id: 23035,
value: {
Name: 'Long Road Leads Home',
},
},
],
RelicSets: [],
},
}

type betaInformation = Partial<Record<InputLocale, { Characters: Character[];Lightcones: LightCone[];RelicSets: RelicSet[] }>>
type Character = { key: number; value: { Name: string } }
type LightCone = { id: number; value: { Name: string } }
type RelicSet = { id: number; value: { Name: string; Description2pc: string; Description4pc?: string } }
Loading

0 comments on commit 285d54c

Please sign in to comment.