3.4 KiB
Localization
Important notice: please don't translate server logs with i18n.*(). It uses the request locale, not the server one.
Quick links to Crowdin
Todo
- Add cookie: Locale
- Rewrite jet template on load to use translated strings
- Add dedicated option to set locale in settings page
- Check if any jet template strings are ignored (false negative)
- Setup Crowdin
- manual upload and download
- automatic upload and download
Crowdin CLI usage
Install the CLI: See official instructions
Remember to check crowdin -V. Should be 4.2.0 or later.
First, setup API token:
- Go to https://crowdin.com/settings#api-key
- Click the "New Token" button
- Set permission: Projects >
- Projects (List, Get, Create, Edit) -- Read only
- Source files & strings (List, Get, Create, Edit) -- Read and write
- Translations (List, Get, Create, Edit) -- Read and write
- Copy the new token and save it somewhere
Then, try it out.
export CROWDIN_PERSONAL_TOKEN=token_here # put this somewhere in your shell config, or the `.env` file inside this repo, which will be used by ./build.sh
crowdin upload
crowdin download
Crowdin Docker usage
These instructions assume CROWDIN_PERSONAL_TOKEN is available as an environment variable.
Step 1: set up container (with sources from local git repo)
Create an interactive Docker container using the crowdin/cli:latest image, and mount ./i18n/locale/en from the local Git repository to /usr/crowdin-project/i18n/locale/en inside the container.
docker run -it --rm --name crowdin-cli \
-e CROWDIN_PERSONAL_TOKEN=${CROWDIN_PERSONAL_TOKEN} \
-v "./i18n/locale/en:/usr/crowdin-project/i18n/locale/en" \
crowdin/cli:latest
Step 2: init crowdin.yml
Initialise crowdin.yml; we don't need explicitly set --quiet as an option as we define all required configuration in crowdin init.
crowdin init \
--token "${CROWDIN_PERSONAL_TOKEN}" \
--project-id "724667" \
--base-path "." \
--base-url "https://api.crowdin.com" \
--source "/i18n/locale/en/*.json" \
--translation "/i18n/locale/%locale%/%original_file_name%" \
--verbose
Step 3: upload translations from container to PixivFE crowdin project
crowdin upload \
--verbose
Step 4: download translations from PixivFE crowdin project to container
crowdin download \
--verbose
Crowdin Web UI usage
Add new languages to translate in Settings > Languages.
./i18n/crawler -- Primer on html and jet's treatment of templates
<a>abc {{.Hi}}</a>
html: abc {{.Hi}} is text
jet: <a>abc is text
jet: </a> is text
So, jet doesn't care about HTML.
And we have to care about {* *} comments.
./i18n/crawler -- Coalesce inline tags
Example: in below, the <a> tag should be part of the string.
Log in with your Pixiv account's cookie to access features above. To learn how to obtain your cookie, please see <a href="https://pixivfe-docs.pages.dev/obtaining-pixivfe-token/">the guide on obtaining your PixivFE token</a>.
Tags to consider as inline: a