diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 78e0bd4c4f..2899f9b149 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -7,6 +7,10 @@ runs: uses: actions/setup-node@v4 with: node-version: 18.16.0 + - name: Install yarn + run: npm install -g yarn + shell: bash + if: ${{ env.ACT }} - name: Cache uses: actions/cache@v4 id: cache diff --git a/.github/workflows/i18n-string-extract-master.yml b/.github/workflows/i18n-string-extract-master.yml new file mode 100644 index 0000000000..ed413cd470 --- /dev/null +++ b/.github/workflows/i18n-string-extract-master.yml @@ -0,0 +1,36 @@ +name: Extract and upload i18n strings + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + extract-and-upload-i18n-strings: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up environment + uses: ./.github/actions/setup + - name: Configure i18n client + run: | + pip install wlc + - name: Generate i18n strings + run: yarn generate:i18n + - name: Upload i18n strings + run: | + if [[ ! -f packages/desktop-client/locale/en.json ]]; then + echo "File packages/desktop-client/locale/en.json not found. Ensure the file was generated correctly." + exit 1 + fi + wlc \ + --url https://hosted.weblate.org/api/ \ + --key "${{ secrets.WEBLATE_API_KEY_CI_STRINGS }}" \ + upload \ + --author-name "Actual Budget" \ + --author-email "dev@actualbudget.org" \ + --method add \ + --input packages/desktop-client/locale/en.json \ + actualbudget/actual/en + echo "Translations uploaded" diff --git a/packages/desktop-client/.gitignore b/packages/desktop-client/.gitignore index d00b9758da..a67335f517 100644 --- a/packages/desktop-client/.gitignore +++ b/packages/desktop-client/.gitignore @@ -25,3 +25,6 @@ public/kcab public/data public/data-file-index.txt public/*.wasm + +# translations +locale/ diff --git a/packages/desktop-client/i18next-parser.config.js b/packages/desktop-client/i18next-parser.config.js index eaab75dae0..9295dbf0ad 100644 --- a/packages/desktop-client/i18next-parser.config.js +++ b/packages/desktop-client/i18next-parser.config.js @@ -1,6 +1,6 @@ module.exports = { input: ['src/**/*.{js,jsx,ts,tsx}', '../loot-core/src/**/*.{js,jsx,ts,tsx}'], - output: 'src/locale/$LOCALE.json', + output: 'locale/$LOCALE.json', locales: ['en'], sort: true, keySeparator: false, diff --git a/packages/desktop-client/src/i18n.ts b/packages/desktop-client/src/i18n.ts index e0a2100b28..27af3ecac8 100644 --- a/packages/desktop-client/src/i18n.ts +++ b/packages/desktop-client/src/i18n.ts @@ -3,8 +3,15 @@ import { initReactI18next } from 'react-i18next'; import i18n from 'i18next'; import resourcesToBackend from 'i18next-resources-to-backend'; +const languages = import.meta.glob('/locale/*.json'); + const loadLanguage = (language: string) => { - return import(`./locale/${language}.json`); + const path = `/locale/${language}.json`; + if (!Object.hasOwn(languages, path)) { + console.error(`Unknown locale ${language}`); + throw new Error(`Unknown locale ${language}`); + } + return languages[path](); }; i18n diff --git a/upcoming-release-notes/4002.md b/upcoming-release-notes/4002.md new file mode 100644 index 0000000000..0f17747c26 --- /dev/null +++ b/upcoming-release-notes/4002.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [jfdoming] +--- + +Upload translations after changes are merged