Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor translations for easier editing #917

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ module.exports = {
rules: {
"@typescript-eslint/no-var-requires": "off" // Disable this specific rule for CJS files
}
},
{
files: ['src/i18n/**/translations.ts'],
rules: {
"internal-rules/check-i18n-keys": "off" //Disabled so no warnings are presented everytime pre-commit is run
}
},
}
],
parser: "@typescript-eslint/parser",
parserOptions: {
Expand All @@ -38,7 +32,7 @@ module.exports = {
jsx: true
}
},
plugins: ["@typescript-eslint", "solid", "import", "internal-rules"],
plugins: ["@typescript-eslint", "solid", "import"],
rules: {
"@typescript-eslint/no-unused-vars": [
"warn",
Expand Down
33 changes: 10 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,41 +131,28 @@ just i18n $lang

### Adding new languages or keys

1. In `src/i18n/` locate your desired language folder or create one if one does not exist
1. In `public/i18n/` locate your desired language .json file or create one if one does not exist

- When creating a new language dir ensure it follows the ISO 639 2-letter standard
- When creating a new language file ensure it follows the ISO 639 2-letter standard

2. In this folder create a file called `translations.ts`, this is where the translation keys for your desired language will be located
2. Populate your translation file with a translation object where all of the keys will be located

3. Populate your translation file with a translation object where all of the keys will be located

If you want to add Japanese you will create a file `/src/i18n/jp/translations.ts` and populate it with keys like so:
If you want to add Japanese you will create a file `/public/i18n/jp.json` and populate it with keys like so:

```
export default {
common: {
continue: "続ける",
{
"common": {
"continue": "続ける",
...
}
}
```

(You should compare your translations against the English language as all other languages are not the master and are likely deprecated)

4. Add your new translation file to the `/src/i18n/config.ts` so you can begin to see them in the app

```
import fa from "~/i18n/jp/translations.ts"

export const resources: {
...
jp: {
translations: jp
}
}
```
If you're using VS Code there are some nice extensions that can make this easier like i18n-ally and i18n-json-editor

5. Add your language to the `Language` object in `/src/utils/languages.ts`. This will allow you to select the language via the language selector in the UI. If your desired language is set as your primary language in your browser it will be selected automatically
3. Add your language to the `Language` object in `/src/utils/languages.ts`. This will allow you to select the language via the language selector in the UI. If your desired language is set as your primary language in your browser it will be selected automatically

```
export const LANGUAGE_OPTIONS: Language[] = [
Expand All @@ -175,4 +162,4 @@ export const LANGUAGE_OPTIONS: Language[] = [
},
```

6. That's it! You should now be able to see your translation keys populating the app in your desired language. When youre ready go ahead and open a PR to have you language merged for others!
4. That's it! You should now be able to see your translation keys populating the app in your desired language. When youre ready go ahead and open a PR to have you language merged for others!
4 changes: 0 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ dev:
pre:
pnpm run pre-commit

i18n LANG:
#!/usr/bin/env bash
pnpm eslint-path "./src/i18n/{{LANG}}/translations.ts" --rule "{internal-rules/check-i18n-keys: warn}"

local:
pnpm install && pnpm link --global "@mutinywallet/mutiny-wasm"

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"check-types": "tsc --noemit",
"eslint": "eslint src",
"eslint-path": "eslint",
"check-i18n-keys": "eslint src/i18n/**/translations.ts --rule \"{internal-rules/check-i18n-keys: warn}\"",
"pre-commit": "pnpm eslint && pnpm run check-types && pnpm run format",
"format": "prettier --write \"{.,src/**,e2e/**}/*.{ts,tsx,js,jsx,json,css,scss,md}\"",
"check-format": "prettier --check \"src/**/*.{ts,tsx,js,jsx,json,css,scss,md}\""
Expand All @@ -28,7 +27,6 @@
"eslint": "^8.52.0",
"eslint-import-resolver-typescript": "2.7.1",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-internal-rules": "file:tools/internal-rules",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-solid": "0.13.0",
"postcss": "^8.4.31",
Expand All @@ -43,6 +41,7 @@
"workbox-window": "^7.0.0"
},
"dependencies": {
"i18next-http-backend": "^2.5.0",
"@capacitor-mlkit/barcode-scanning": "^5.3.0",
"@capacitor/android": "^5.5.1",
"@capacitor/app": "^5.0.6",
Expand All @@ -63,7 +62,7 @@
"@solid-primitives/upload": "^0.0.111",
"@solidjs/meta": "^0.29.1",
"@solidjs/router": "^0.9.0",
"i18next": "^22.5.1",
"i18next": "^23.10.1",
"i18next-browser-languagedetector": "^7.1.0",
"qr-scanner": "^1.4.2",
"solid-js": "^1.8.5",
Expand Down
51 changes: 23 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading