From 802405352015d8b0c1fb7659ce50af29f5ba8ee5 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Mon, 10 Oct 2022 21:38:37 +0200 Subject: [PATCH 1/5] Install i18n-js 4 --- Gemfile | 2 +- Gemfile.lock | 8 +++++--- package.json | 2 +- yarn.lock | 18 +++++++++++++----- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index c8feaa55..c5b29c96 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "i18n-js", "3.9.2" +gem "i18n-js", "4.0" gem "rails", "~> 6.1" gem "rails-i18n", "~> 6.0" diff --git a/Gemfile.lock b/Gemfile.lock index 4cb74796..e212e0da 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -197,6 +197,7 @@ GEM fog-core nokogiri (>= 1.5.11, < 2.0.0) formatador (1.1.0) + glob (0.3.1) globalid (1.0.0) activesupport (>= 5.0) guard (2.18.0) @@ -241,8 +242,9 @@ GEM multi_xml (>= 0.5.2) i18n (1.12.0) concurrent-ruby (~> 1.0) - i18n-js (3.9.2) - i18n (>= 0.6.6) + i18n-js (4.0.0) + glob + i18n idn-ruby (0.1.4) image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) @@ -597,7 +599,7 @@ DEPENDENCIES haml_lint hcaptcha (~> 7.0) httparty - i18n-js (= 3.9.2) + i18n-js (= 4.0) jbuilder (~> 2.10) jwt (~> 2.5) letter_opener diff --git a/package.json b/package.json index 6ee4a84e..1e7df09d 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "core-js": "^3.25.5", "croppr": "^2.3.1", "font-awesome": "4.7.0", - "i18n-js": "^3.9.2", + "i18n-js": "^4.0", "jquery": "^3.6.1", "js-cookie": "2.2.1", "lato-font": "^3.0.0", diff --git a/yarn.lock b/yarn.lock index d40aa9a6..f380abdb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1990,6 +1990,11 @@ big.js@^5.2.2: resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328" integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ== +bignumber.js@*: + version "9.1.0" + resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.0.tgz#8d340146107fe3a6cb8d40699643c302e8773b62" + integrity sha512-4LwHK4nfDOraBCtst+wOWIHbu1vhvAPJK8g8nROd4iuc3PSEjWif/qwbkh8jwCJz6yDBvtU4KPynETgrfh7y3A== + binary-extensions@^1.0.0: version "1.13.1" resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65" @@ -4157,10 +4162,13 @@ human-signals@^2.1.0: resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0" integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw== -i18n-js@^3.9.2: - version "3.9.2" - resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-3.9.2.tgz#4a015dcfabd4c9fc73115fc2d02d2627e4c15ca5" - integrity sha512-+Gm8h5HL0emzKhRx2avMKX+nKiVPXeaOZm7Euf2/pbbFcLQoJ3zZYiUykAzoRasijCoWos2Kl1tslmScTgAQKw== +i18n-js@^4.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-4.1.1.tgz#05ebd03c4d92f6dc26a00d7c5cfb90f9c326b67c" + integrity sha512-Uph8ghmfShexVhDcNtg5s40zprJZPrhW5iOEKsUwPiiBpIGN/0EJ9W7DTqhLFlWfAlpkFiaLxVxHsk8f+3KjIQ== + dependencies: + bignumber.js "*" + lodash "*" iconv-lite@0.4.24: version "0.4.24" @@ -4839,7 +4847,7 @@ lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@^4.17.5: +lodash@*, lodash@^4.17.5: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== From bee89d367ca219f1ba92a64223c18525a7690776 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 17 Sep 2022 15:18:55 +0200 Subject: [PATCH 2/5] Adjust Github Action locale export step --- .github/workflows/retrospring.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/retrospring.yml b/.github/workflows/retrospring.yml index 5126ac3d..d0147b68 100644 --- a/.github/workflows/retrospring.yml +++ b/.github/workflows/retrospring.yml @@ -61,7 +61,7 @@ jobs: npm i -g yarn yarn install --frozen-lockfile - name: Export i18n JS files - run: bundle exec rails i18n:js:export + run: bundle exec i18n export - name: Compile assets run: bundle exec rake assets:precompile From a8c1961af3d0b33319321b587efa1711ffbfefd2 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 17 Sep 2022 15:17:07 +0200 Subject: [PATCH 3/5] Migrate entrypoint to support new i18n-js version --- app/javascript/retrospring/i18n.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/javascript/retrospring/i18n.ts diff --git a/app/javascript/retrospring/i18n.ts b/app/javascript/retrospring/i18n.ts new file mode 100644 index 00000000..0af48928 --- /dev/null +++ b/app/javascript/retrospring/i18n.ts @@ -0,0 +1,12 @@ + +import Cookies from 'js-cookie' +import { I18n } from "i18n-js" +import translations from "./i18n.json"; + +const i18n = new I18n(); +i18n.store(translations); +i18n.defaultLocale = "en"; +i18n.enableFallback = true; +i18n.locale = Cookies.get('hl') || 'en'; + +export default i18n; From 591a912666fd2b2c34c63ffb28c4dcc779c7d3de Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 17 Sep 2022 15:16:41 +0200 Subject: [PATCH 4/5] Make i18n-js configuration compatible with 4.x --- .gitignore | 2 +- config/{i18n-js.yml => i18n.yml} | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) rename config/{i18n-js.yml => i18n.yml} (68%) diff --git a/.gitignore b/.gitignore index 46743497..499e744c 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,7 @@ coverage/ *~ # dont push generated js translations to repository -/app/javascript/retrospring/i18n.ts +/app/javascript/retrospring/i18n.json # every fucking time, dolphin .directory diff --git a/config/i18n-js.yml b/config/i18n.yml similarity index 68% rename from config/i18n-js.yml rename to config/i18n.yml index 0a5cdfa3..c4b7c90d 100644 --- a/config/i18n-js.yml +++ b/config/i18n.yml @@ -21,12 +21,9 @@ # If you're running an old version, you can use something # like this: # -fallbacks: :default_locale - -export_i18n_js: false - translations: - - file: 'app/javascript/retrospring/i18n.ts' - only: ['*.voc.*', '*.frontend.*', '*.views.actions.*'] - prefix: "import I18n from 'i18n-js'\nimport Cookies from 'js-cookie'\n" - suffix: "I18n.defaultLocale = 'en';\nI18n.locale = Cookies.get('hl') || 'en';\nexport default I18n" + - file: 'app/javascript/retrospring/i18n.json' + patterns: + - '*.voc.*' + - '*.frontend.*' + - '*.views.actions.*' From 18c876138dc6297c75fc1b2d0f145a224bd446b5 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 17 Sep 2022 15:15:49 +0200 Subject: [PATCH 5/5] Allow importing JSON files in TypeScript --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index 6ec41c38..1b43475d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "lib": ["es6", "dom"], "module": "es6", "moduleResolution": "node", + "resolveJsonModule": true, "baseUrl": ".", "paths": { "*": ["node_modules/*", "app/javascript/*"],