From 8aa88776bf0d4cd344223d653767b2d428453564 Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Wed, 21 Feb 2018 21:47:57 +0200 Subject: [PATCH 01/18] Add support for culture --- packages/core/src/select.js | 13 +++++++++++-- packages/core/src/select.test.js | 24 ++++++++++++++++++++++++ packages/react/src/Select.js | 3 ++- packages/react/src/Select.test.js | 14 ++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/packages/core/src/select.js b/packages/core/src/select.js index 935253f5f..4d2b71e8b 100644 --- a/packages/core/src/select.js +++ b/packages/core/src/select.js @@ -11,21 +11,30 @@ type PluralForms = { type PluralProps = { value: number, - offset?: number + offset?: number, + culture?: string } & PluralForms +declare var Intl: { + NumberFormat: any +} + const _plural = type => (i18n: any) => ({ value, offset = 0, + culture = "en-UK", other, ...pluralForms }: PluralProps): string => { + console.log(culture) const diff = value - offset + const intl = new Intl.NumberFormat(culture) + const diffAsString = intl.format(diff) const translation = pluralForms[value.toString()] || // exact match pluralForms[i18n.pluralForm(diff, type)] || // plural form other // fallback - return translation.replace("#", diff.toString()) + return translation.replace("#", diffAsString) } const plural = _plural("cardinal") diff --git a/packages/core/src/select.test.js b/packages/core/src/select.test.js index 4d1cc38c4..3eb6a1fe0 100644 --- a/packages/core/src/select.test.js +++ b/packages/core/src/select.test.js @@ -49,6 +49,30 @@ describe("plural", function() { other: "Their and # books" }) ).toEqual("Their and 4 books") + + expect( + p({ + value: 1, + other: "# كتاب", + culture: "ar" + }) + ).toEqual("١ " + "كتاب") + + expect( + p({ + value: 1, + other: "# كتاب", + culture: "en" + }) + ).toEqual("1 " + "كتاب") + + expect( + p({ + value: 1, + other: "# كتاب", + culture: "ar-AS" + }) + ).toEqual("١ " + "كتاب") }) }) diff --git a/packages/react/src/Select.js b/packages/react/src/Select.js index 69d52483f..262556670 100644 --- a/packages/react/src/Select.js +++ b/packages/react/src/Select.js @@ -14,7 +14,8 @@ type PluralProps = { two?: any, few?: any, many?: any, - other: any + other: any, + culture?: string } & withI18nProps & RenderProps diff --git a/packages/react/src/Select.test.js b/packages/react/src/Select.test.js index 9f12c6663..b2e20fbc7 100644 --- a/packages/react/src/Select.test.js +++ b/packages/react/src/Select.test.js @@ -74,6 +74,20 @@ describe("Categories", function() { expect(t()).toEqual("5 knih") }) + it("should use plural forms based on culture", function() { + const node = mount( + , + languageContext("de") + ) + + const t = () => node.find("Render").text() + + expect(t()).toEqual("1.000") + + node.setProps({ value: 2000 }) + expect(t()).toEqual("2.000") + }) + it("should offset value", function() { const node = mount( Date: Thu, 22 Feb 2018 13:51:15 +0200 Subject: [PATCH 02/18] Use full culture names like de-DE or ar-AS instead of de or ar only --- packages/core/src/select.js | 1 - packages/core/src/select.test.js | 14 +++----------- packages/react/src/Select.test.js | 2 +- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/packages/core/src/select.js b/packages/core/src/select.js index 4d2b71e8b..690f0ae8d 100644 --- a/packages/core/src/select.js +++ b/packages/core/src/select.js @@ -26,7 +26,6 @@ const _plural = type => (i18n: any) => ({ other, ...pluralForms }: PluralProps): string => { - console.log(culture) const diff = value - offset const intl = new Intl.NumberFormat(culture) const diffAsString = intl.format(diff) diff --git a/packages/core/src/select.test.js b/packages/core/src/select.test.js index 3eb6a1fe0..9c5bf7486 100644 --- a/packages/core/src/select.test.js +++ b/packages/core/src/select.test.js @@ -54,17 +54,9 @@ describe("plural", function() { p({ value: 1, other: "# كتاب", - culture: "ar" + culture: "en-UK" }) - ).toEqual("١ " + "كتاب") - - expect( - p({ - value: 1, - other: "# كتاب", - culture: "en" - }) - ).toEqual("1 " + "كتاب") + ).toEqual("1 كتاب") expect( p({ @@ -72,7 +64,7 @@ describe("plural", function() { other: "# كتاب", culture: "ar-AS" }) - ).toEqual("١ " + "كتاب") + ).toEqual("١ كتاب") }) }) diff --git a/packages/react/src/Select.test.js b/packages/react/src/Select.test.js index b2e20fbc7..e82c1d637 100644 --- a/packages/react/src/Select.test.js +++ b/packages/react/src/Select.test.js @@ -76,7 +76,7 @@ describe("Categories", function() { it("should use plural forms based on culture", function() { const node = mount( - , + , languageContext("de") ) From 99a400de5786fc2172a0c5cd5462e4fdde6ae98c Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Fri, 23 Feb 2018 16:06:03 +0200 Subject: [PATCH 03/18] Changing the pattern of the ar-AS test to prevent the move of the numeral position --- packages/core/src/select.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/select.test.js b/packages/core/src/select.test.js index 9c5bf7486..fec2a1c63 100644 --- a/packages/core/src/select.test.js +++ b/packages/core/src/select.test.js @@ -61,10 +61,10 @@ describe("plural", function() { expect( p({ value: 1, - other: "# كتاب", + other: "لدي # كتاب", culture: "ar-AS" }) - ).toEqual("١ كتاب") + ).toEqual("لدي ١ كتاب") }) }) From 33c564e4dd47fbe32c73ac77cf88ba709c3de4ca Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Fri, 23 Feb 2018 16:52:32 +0200 Subject: [PATCH 04/18] Run tests with full-icu --- appveyor.yml | 3 ++- circle.yml | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b5014269d..94794e873 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,6 +5,7 @@ environment: install: # Get the latest stable version of Node.js or io.js - ps: Install-Product node $env:nodejs_version + - yarn add full-icu -W # install modules - yarn install - yarn global add yalc @@ -15,7 +16,7 @@ test_script: - node --version - yarn --version # run tests - - node scripts/test.js + - NODE_ICU_DATA=./node_modules/full-icu node scripts/test.js # Don't actually build. build: off diff --git a/circle.yml b/circle.yml index 10d6c925c..88286121c 100644 --- a/circle.yml +++ b/circle.yml @@ -34,12 +34,16 @@ jobs: name: Install dependencies command: yarn install + - run: + name: Embed the entire ICU (full-icu) + command: yarn add full-icu -W + - save_cache: key: node-modules-{{ checksum "yarn.lock" }} paths: - node_modules - - run: node scripts/test.js + - run: NODE_ICU_DATA=./node_modules/full-icu node scripts/test.js - run: name: Send coverage report From e2576a8eb1b546c39841369b9a6f43ac728aa6ee Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Fri, 23 Feb 2018 17:28:45 +0200 Subject: [PATCH 05/18] Trying to fix the CIs --- appveyor.yml | 2 +- circle.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 94794e873..9185b508b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,7 @@ test_script: - node --version - yarn --version # run tests - - NODE_ICU_DATA=./node_modules/full-icu node scripts/test.js + - env NODE_ICU_DATA=./node_modules/full-icu node scripts/test.js # Don't actually build. build: off diff --git a/circle.yml b/circle.yml index 88286121c..32de97ec6 100644 --- a/circle.yml +++ b/circle.yml @@ -43,6 +43,8 @@ jobs: paths: - node_modules + - run: npm list --depth=0 + - run: NODE_ICU_DATA=./node_modules/full-icu node scripts/test.js - run: From 4da056a1a5be00f6a9183b6cd8ab42ab05ada78f Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Fri, 23 Feb 2018 17:53:07 +0200 Subject: [PATCH 06/18] Trying to fix the CIs: install full-icu before the rest of the packages and pass the path to icu using argument instead of env variable --- appveyor.yml | 2 +- circle.yml | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 9185b508b..213f59bf0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,7 @@ test_script: - node --version - yarn --version # run tests - - env NODE_ICU_DATA=./node_modules/full-icu node scripts/test.js + - node --icu-data-dir=node_modules/full-icu scripts/test.js # Don't actually build. build: off diff --git a/circle.yml b/circle.yml index 32de97ec6..97ce146d4 100644 --- a/circle.yml +++ b/circle.yml @@ -31,20 +31,18 @@ jobs: key: node-modules-{{ checksum "yarn.lock" }} - run: - name: Install dependencies - command: yarn install + name: Add the entire ICU (full-icu) + command: yarn add full-icu -W - run: - name: Embed the entire ICU (full-icu) - command: yarn add full-icu -W + name: Install dependencies + command: yarn install - save_cache: key: node-modules-{{ checksum "yarn.lock" }} paths: - node_modules - - run: npm list --depth=0 - - run: NODE_ICU_DATA=./node_modules/full-icu node scripts/test.js - run: From 633964ee9296eff34be7ce4685b83c982abfbf07 Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Fri, 23 Feb 2018 18:02:59 +0200 Subject: [PATCH 07/18] Trying to fix the CIs: testing icu --- .gitignore | 2 ++ circle.yml | 2 +- packages/core/src/select.test.js | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5bef4823d..a8644b011 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ results/ junit.xml __pycache__/ + +.DS_Store diff --git a/circle.yml b/circle.yml index 97ce146d4..2ea73e495 100644 --- a/circle.yml +++ b/circle.yml @@ -43,7 +43,7 @@ jobs: paths: - node_modules - - run: NODE_ICU_DATA=./node_modules/full-icu node scripts/test.js + - run: node --icu-data-dir=node_modules/full-icu scripts/test.js - run: name: Send coverage report diff --git a/packages/core/src/select.test.js b/packages/core/src/select.test.js index fec2a1c63..de18c37cb 100644 --- a/packages/core/src/select.test.js +++ b/packages/core/src/select.test.js @@ -2,6 +2,19 @@ import { plural, select, selectOrdinal } from "./select" import { setupI18n } from "@lingui/core" +const hasFullICU = (() => { + try { + const january = new Date(9e8); + const spanish = new Intl.DateTimeFormat('es', { month: 'long' }); + return spanish.format(january) === 'enero'; + } catch (err) { + console.log(err) + return false; + } +})(); + +console.log("hasFullICU:", hasFullICU) + describe("plural", function() { const i18n = setupI18n({ language: "en", From cd903d75973549918cc6e6a7bb5f3417d87848df Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 11:52:14 +0200 Subject: [PATCH 08/18] Fixing CIs: installing full-icu with node --- circle.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 2ea73e495..f149d44e4 100644 --- a/circle.yml +++ b/circle.yml @@ -31,13 +31,17 @@ jobs: key: node-modules-{{ checksum "yarn.lock" }} - run: - name: Add the entire ICU (full-icu) - command: yarn add full-icu -W + name: Add the entire ICU (full-icu) 1 + command: node install full-icu - run: name: Install dependencies command: yarn install + - run: + name: Add the entire ICU (full-icu) 2 + command: node install full-icu + - save_cache: key: node-modules-{{ checksum "yarn.lock" }} paths: From 29f4f366e187ef0b913540f21c0eef11db9798f4 Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 11:56:21 +0200 Subject: [PATCH 09/18] Fixing CIs: don't lint --- circle.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index f149d44e4..2bd013a10 100644 --- a/circle.yml +++ b/circle.yml @@ -4,11 +4,11 @@ workflows: version: 2 test_n_deploy: jobs: - - test-linter +# - test-linter - test-node8: - requires: - - test-linter +# requires: +# - test-linter # - build-docs: # requires: From 038d6990a341bddbe49f3b1235ba87e844e4f2da Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 13:01:48 +0200 Subject: [PATCH 10/18] Fixing CIs: force CI build --- circle.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/circle.yml b/circle.yml index 2bd013a10..196677afd 100644 --- a/circle.yml +++ b/circle.yml @@ -10,11 +10,6 @@ workflows: # requires: # - test-linter -# - build-docs: -# requires: -# - test-node6 -# - test-node8 - jobs: test-node8: &test-template docker: From f8108e0b911cdfec41f95a75a7a9008b615d2ada Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 13:06:25 +0200 Subject: [PATCH 11/18] Fixing CIs: cleanup yml file --- circle.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index 196677afd..5360440a7 100644 --- a/circle.yml +++ b/circle.yml @@ -4,12 +4,17 @@ workflows: version: 2 test_n_deploy: jobs: -# - test-linter - - - test-node8: + - test-node8 # requires: # - test-linter +# - build-docs: +# requires: +# - test-node6 +# - test-node8 + + - test-linter + jobs: test-node8: &test-template docker: From 829c64455635ebdf9217343d3b1a5bf9a8d39b40 Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 13:10:33 +0200 Subject: [PATCH 12/18] Fixing CIs: fix install command --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 5360440a7..3a47e1cfc 100644 --- a/circle.yml +++ b/circle.yml @@ -32,7 +32,7 @@ jobs: - run: name: Add the entire ICU (full-icu) 1 - command: node install full-icu + command: npm install full-icu - run: name: Install dependencies From 1fec503cdd815a63db758ff91ae43630815e31e3 Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 13:16:20 +0200 Subject: [PATCH 13/18] Fixing CIs: fix install command 2 --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 3a47e1cfc..7a999785e 100644 --- a/circle.yml +++ b/circle.yml @@ -40,7 +40,7 @@ jobs: - run: name: Add the entire ICU (full-icu) 2 - command: node install full-icu + command: npm install full-icu - save_cache: key: node-modules-{{ checksum "yarn.lock" }} From 7195a1f096881416e2733027f18abc11803ca751 Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 13:22:02 +0200 Subject: [PATCH 14/18] Fixing CIs: fix install command 3 --- circle.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/circle.yml b/circle.yml index 7a999785e..b088e6f63 100644 --- a/circle.yml +++ b/circle.yml @@ -4,6 +4,8 @@ workflows: version: 2 test_n_deploy: jobs: + - test-linter + - test-node8 # requires: # - test-linter @@ -13,8 +15,6 @@ workflows: # - test-node6 # - test-node8 - - test-linter - jobs: test-node8: &test-template docker: @@ -31,16 +31,16 @@ jobs: key: node-modules-{{ checksum "yarn.lock" }} - run: - name: Add the entire ICU (full-icu) 1 - command: npm install full-icu + name: Add the entire ICU (full-icu) + command: yarn add full-icu -W - run: name: Install dependencies command: yarn install - run: - name: Add the entire ICU (full-icu) 2 - command: npm install full-icu + name: Add the entire ICU (full-icu) + command: yarn add full-icu -W - save_cache: key: node-modules-{{ checksum "yarn.lock" }} From 805e956b48d79ea46fba5c0cfd457f13fd6c13ed Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 13:25:56 +0200 Subject: [PATCH 15/18] Fixing CIs: fix install command 4 --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index b088e6f63..eeaa47bca 100644 --- a/circle.yml +++ b/circle.yml @@ -47,7 +47,7 @@ jobs: paths: - node_modules - - run: node --icu-data-dir=node_modules/full-icu scripts/test.js + - run: env NODE_ICU_DATA=/node_modules/full-icu node scripts/test.js - run: name: Send coverage report From 6b9e1b2352d5e5dbb9d6a7cd29345d2ea9b2c97c Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 19:49:59 +0200 Subject: [PATCH 16/18] Fixing CIs: using nvm to reinstall node with full-icu --- circle.yml | 26 +++++++++++++++++++++----- test-full-icu.js | 2 ++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 test-full-icu.js diff --git a/circle.yml b/circle.yml index eeaa47bca..2a7e06e3b 100644 --- a/circle.yml +++ b/circle.yml @@ -23,6 +23,26 @@ jobs: steps: - checkout + - run: + name: Print node version + command: node -v + + - run: + name: List installed node versions + command: nvm ls + + - run: + name: (Re)Install node with full-icu + command: nvm install -s v8 --with-intl=full-icu --download=all + + - run: + name: Print node version again + command: node -v + + - run: + name: Testing full-icu + command: node test-full-icu.js + - run: name: Install build tools command: sudo yarn global add codecov yalc @@ -32,16 +52,12 @@ jobs: - run: name: Add the entire ICU (full-icu) - command: yarn add full-icu -W + command: npm install full-icu - run: name: Install dependencies command: yarn install - - run: - name: Add the entire ICU (full-icu) - command: yarn add full-icu -W - - save_cache: key: node-modules-{{ checksum "yarn.lock" }} paths: diff --git a/test-full-icu.js b/test-full-icu.js new file mode 100644 index 000000000..d06f6f709 --- /dev/null +++ b/test-full-icu.js @@ -0,0 +1,2 @@ +console.log("*** Testing full-icu ***"); +console.log(new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8))); From 583a6b2028fd939c1be635d350d5030e5e0ed643 Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 20:16:13 +0200 Subject: [PATCH 17/18] Fixing CIs: using a different path --- circle.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/circle.yml b/circle.yml index 2a7e06e3b..178d40981 100644 --- a/circle.yml +++ b/circle.yml @@ -28,20 +28,16 @@ jobs: command: node -v - run: - name: List installed node versions - command: nvm ls - - - run: - name: (Re)Install node with full-icu - command: nvm install -s v8 --with-intl=full-icu --download=all + name: Print node version + command: npm install full-icu - run: - name: Print node version again - command: node -v + name: pwd + command: pwd - run: name: Testing full-icu - command: node test-full-icu.js + command: env NODE_ICU_DATA=./node_modules/full-icu node test-full-icu.js - run: name: Install build tools @@ -63,7 +59,7 @@ jobs: paths: - node_modules - - run: env NODE_ICU_DATA=/node_modules/full-icu node scripts/test.js + - run: env NODE_ICU_DATA=./node_modules/full-icu node scripts/test.js - run: name: Send coverage report From 775600148cdb275c906cfa27d95b6da76d9d29d6 Mon Sep 17 00:00:00 2001 From: Cristi Ingineru Date: Sun, 25 Feb 2018 20:22:33 +0200 Subject: [PATCH 18/18] Fixing CIs: testing ICU more times --- circle.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 178d40981..ccd849c47 100644 --- a/circle.yml +++ b/circle.yml @@ -47,18 +47,26 @@ jobs: key: node-modules-{{ checksum "yarn.lock" }} - run: - name: Add the entire ICU (full-icu) - command: npm install full-icu + name: Testing full-icu + command: env NODE_ICU_DATA=./node_modules/full-icu node test-full-icu.js - run: name: Install dependencies command: yarn install + - run: + name: Testing full-icu + command: env NODE_ICU_DATA=./node_modules/full-icu node test-full-icu.js + - save_cache: key: node-modules-{{ checksum "yarn.lock" }} paths: - node_modules + - run: + name: Testing full-icu + command: env NODE_ICU_DATA=./node_modules/full-icu node test-full-icu.js + - run: env NODE_ICU_DATA=./node_modules/full-icu node scripts/test.js - run: