From ca22b67dd2c44ef3f8287bd310e5aec17dfb7e63 Mon Sep 17 00:00:00 2001 From: stevenlele Date: Fri, 17 Mar 2023 20:15:42 +0800 Subject: [PATCH 1/4] Fix locale parsing --- Library/Homebrew/locale.rb | 4 ++-- Library/Homebrew/test/locale_spec.rb | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb index eefbc464f8..40647ea62c 100644 --- a/Library/Homebrew/locale.rb +++ b/Library/Homebrew/locale.rb @@ -47,12 +47,12 @@ class Locale return if (sep && scanner.eos?) || (sep.nil? && !scanner.eos?) end - if (region = scanner.scan(REGION_REGEX)) + if (script = scanner.scan(SCRIPT_REGEX)) sep = scanner.scan(/-/) return if (sep && scanner.eos?) || (sep.nil? && !scanner.eos?) end - script = scanner.scan(SCRIPT_REGEX) + region = scanner.scan(REGION_REGEX) return unless scanner.eos? diff --git a/Library/Homebrew/test/locale_spec.rb b/Library/Homebrew/test/locale_spec.rb index e704fe87b0..8cd7d9938d 100644 --- a/Library/Homebrew/test/locale_spec.rb +++ b/Library/Homebrew/test/locale_spec.rb @@ -9,7 +9,7 @@ describe Locale do expect(described_class.parse("zh")).to eql(described_class.new("zh", nil, nil)) expect(described_class.parse("zh-CN")).to eql(described_class.new("zh", "CN", nil)) expect(described_class.parse("zh-Hans")).to eql(described_class.new("zh", nil, "Hans")) - expect(described_class.parse("zh-CN-Hans")).to eql(described_class.new("zh", "CN", "Hans")) + expect(described_class.parse("zh-Hans-CN")).to eql(described_class.new("zh", "CN", "Hans")) end it "correctly parses a string with a UN M.49 region code" do @@ -22,6 +22,7 @@ describe Locale do end it "a string in a wrong format" do + expect { described_class.parse("zh-CN-Hans") }.to raise_error(Locale::ParserError) expect { described_class.parse("zh_CN_Hans") }.to raise_error(Locale::ParserError) expect { described_class.parse("zhCNHans") }.to raise_error(Locale::ParserError) expect { described_class.parse("zh-CN_Hans") }.to raise_error(Locale::ParserError) @@ -54,14 +55,14 @@ describe Locale do it { is_expected.to include("CN") } it { is_expected.to include("CN-Hans") } it { is_expected.to include("Hans") } - it { is_expected.to include("zh-CN-Hans") } + it { is_expected.to include("zh-Hans-CN") } end describe "#eql?" do subject(:locale) { described_class.new("zh", "CN", "Hans") } context "when all parts match" do - it { is_expected.to eql("zh-CN-Hans") } + it { is_expected.to eql("zh-Hans-CN") } it { is_expected.to eql(locale) } end @@ -69,7 +70,7 @@ describe Locale do it { is_expected.not_to eql("zh") } it { is_expected.not_to eql("zh-CN") } it { is_expected.not_to eql("CN") } - it { is_expected.not_to eql("CN-Hans") } + it { is_expected.not_to eql("Hans-CN") } it { is_expected.not_to eql("Hans") } end From c5973022d42b891b456b597aa435172f5fd6b457 Mon Sep 17 00:00:00 2001 From: stevenlele Date: Fri, 17 Mar 2023 20:34:25 +0800 Subject: [PATCH 2/4] Update tag order in docs --- docs/Cask-Cookbook.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Cask-Cookbook.md b/docs/Cask-Cookbook.md index c096a442fc..7965868cc9 100644 --- a/docs/Cask-Cookbook.md +++ b/docs/Cask-Cookbook.md @@ -647,7 +647,7 @@ installer script: "#{staged_path}/install.sh" ### Stanza: `language` -The `language` stanza can match [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) language codes, regional identifiers ([ISO 3166-1 Alpha 2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)) and script codes ([ISO 15924](https://en.wikipedia.org/wiki/ISO_15924)), or a combination thereof. +The `language` stanza can match [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) language codes, script codes ([ISO 15924](https://en.wikipedia.org/wiki/ISO_15924)), and regional identifiers ([ISO 3166-1 Alpha 2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)), or a combination thereof. US English should always be used as the default language: From c9e44a0395047c30418b6e2b9ea44dae8aa187f9 Mon Sep 17 00:00:00 2001 From: stevenlele Date: Fri, 17 Mar 2023 20:35:17 +0800 Subject: [PATCH 3/4] Update test --- Library/Homebrew/test/locale_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/locale_spec.rb b/Library/Homebrew/test/locale_spec.rb index 8cd7d9938d..3b627c7705 100644 --- a/Library/Homebrew/test/locale_spec.rb +++ b/Library/Homebrew/test/locale_spec.rb @@ -53,7 +53,7 @@ describe Locale do it { is_expected.to include("zh") } it { is_expected.to include("zh-CN") } it { is_expected.to include("CN") } - it { is_expected.to include("CN-Hans") } + it { is_expected.to include("Hans-CN") } it { is_expected.to include("Hans") } it { is_expected.to include("zh-Hans-CN") } end From b1ddbfee22bb23a410c47ef3d1871279dbe0c673 Mon Sep 17 00:00:00 2001 From: stevenlele Date: Fri, 17 Mar 2023 20:38:26 +0800 Subject: [PATCH 4/4] Remove redundant comma in docs --- docs/Cask-Cookbook.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Cask-Cookbook.md b/docs/Cask-Cookbook.md index 7965868cc9..3d6acb1fb1 100644 --- a/docs/Cask-Cookbook.md +++ b/docs/Cask-Cookbook.md @@ -647,7 +647,7 @@ installer script: "#{staged_path}/install.sh" ### Stanza: `language` -The `language` stanza can match [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) language codes, script codes ([ISO 15924](https://en.wikipedia.org/wiki/ISO_15924)), and regional identifiers ([ISO 3166-1 Alpha 2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)), or a combination thereof. +The `language` stanza can match [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) language codes, script codes ([ISO 15924](https://en.wikipedia.org/wiki/ISO_15924)) and regional identifiers ([ISO 3166-1 Alpha 2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)), or a combination thereof. US English should always be used as the default language: