-
Notifications
You must be signed in to change notification settings - Fork 21
feat(#332): add translation support #744
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
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
775e50e
translate primevue components
latin-panda 6b82dfd
Merge branch 'main' of https://github.com/getodk/web-forms into add-t…
latin-panda 7622e56
add translation logic
latin-panda 30da347
Merge branch 'main' of https://github.com/getodk/web-forms into add-t…
latin-panda b309dac
fixes lint
latin-panda dfab101
Allows locale on form load error
latin-panda 77e442e
add translations
latin-panda d480139
add translations
latin-panda 2e50a81
unit tests
latin-panda a1a43f6
changeset
latin-panda cc4b018
updates comments key
latin-panda 56f65f5
Adds spanish translation from transifex
latin-panda 1fb49b7
fix unit tests
latin-panda c4e56f5
updates release step
latin-panda 0668877
Updates translation docs
latin-panda 0008abb
Move documentation
latin-panda 9c7213b
Merge branch 'main' of https://github.com/getodk/web-forms into add-t…
latin-panda cfc3de8
polishing code
latin-panda 4c0a828
improve spanish
latin-panda 4334a2f
Merge branch 'main' of https://github.com/getodk/web-forms into add-t…
latin-panda d1c9325
feedback part 1: translation keys
latin-panda a9f9dca
feedback part 2: common translation keys
latin-panda 2f72ed4
feedback part 3: adds readme file and warning when using cli tool wrong
latin-panda 25a33e1
feedback part 4: transifex cli config
latin-panda 2c6dcc7
feedback part 5: rename translate function
latin-panda 8d68187
fixes unit tests
latin-panda c49a97f
feedback part 6: regional locales
latin-panda 29a6a19
updates documentation
latin-panda 2b29025
updates spanish translation
latin-panda 63e28e4
Merge branch 'main' of https://github.com/getodk/web-forms into add-t…
latin-panda 60852f7
feedback
latin-panda e6da4c8
Merge branch 'main' of https://github.com/getodk/web-forms into add-t…
latin-panda 2a50d0e
fixes merge conflict
latin-panda a2ef3a7
Merge branch 'main' of https://github.com/getodk/web-forms into add-t…
latin-panda 6899aaa
updates the Transifex project name
latin-panda e813a7a
fix merge conflict
latin-panda 2f6014c
feat(#332): Prioritize form designer's default language (#763)
latin-panda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@getodk/xforms-engine': minor | ||
| '@getodk/web-forms': minor | ||
| --- | ||
|
|
||
| Adds translation support. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [main] | ||
| host = https://app.transifex.com | ||
|
|
||
| [o:getodk:p:web_forms:r:strings] | ||
| file_filter = packages/web-forms/locales/strings_<lang>.json | ||
| source_file = packages/web-forms/locales/strings_en.json | ||
| source_lang = en | ||
| type = STRUCTURED_JSON | ||
| minimum_perc = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Translations | ||
|
|
||
| ## How it works | ||
|
|
||
| Translation strings are defined in `.i18n.json` files co-located with their components. At build time, these files are merged into `locales/strings_en.json`, which serves as the English baseline and is eagerly loaded at runtime. Translations for other locales are loaded lazily when the user switches language. | ||
|
|
||
| Transifex automatically pulls the source strings from `locales/strings_en.json` daily. Translation files are synced back into the project just before each release. | ||
|
|
||
| ## Key naming convention | ||
|
|
||
| Keys follow a 3-part dot-separated pattern: | ||
|
|
||
| ``` | ||
| component.feature.type | ||
| ``` | ||
|
|
||
| - **component**: camelCase name of the Vue component that owns the string (e.g. `odk_web_forms`) | ||
| - **feature**: the feature or section within that component (e.g. `submit`, `validation`) | ||
| - **type**: what kind of string it is. Use one of: | ||
| - `label`: button or field label | ||
| - `title`: heading or title | ||
| - `placeholder`: input placeholder | ||
| - `message`: informational message | ||
| - `error`: error message | ||
|
|
||
| An easy way to remember: **who → where → kind** (which component? which feature? what type of string?). | ||
|
|
||
| ### Examples | ||
|
|
||
| | Key (snake_case) | Description | | ||
| | -------------------------------- | ----------------------- | | ||
| | `odk_web_forms.submit.label` | Submit button label | | ||
| | `odk_web_forms.validation.error` | Validation error banner | | ||
|
|
||
| ## Adding a string | ||
|
|
||
| 1. Create or open the `.i18n.json` file next to the component. | ||
| 2. Add an entry using the `component.feature.type` key convention (snake_case): | ||
|
|
||
| ```json | ||
| { | ||
| "my_component.some_feature.label": { | ||
| "string": "English text here", | ||
| "developer_comment": "Context for translators: when and where this string appears." | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 3. Run `build:translations` to regenerate `locales/strings_en.json`. This also runs automatically as part of the build. | ||
| 4. Use the string in the component via `t('my_component.some_feature.label')`. | ||
|
|
||
| ## Developer comments | ||
|
|
||
| The `developer_comment` optional field is for translators. Explain: | ||
|
|
||
| - Where the string appears in the UI | ||
| - Any placeholders (e.g. `{count}` is the number of violations) | ||
| - Any constraints (e.g. keep it short, it appears on a button) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Locales | ||
|
|
||
| **Do not edit these files directly.** The `strings_en.json` file is auto-generated by `scripts/merge-translations.js`, and the other `strings_[locale].json` files are pulled from the Transifex project. | ||
| The source strings are defined in `.i18n.json` files. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.