Merge pull request #3234 from reitermarkus/locale
Support UN M.49 region codes.
This commit is contained in:
commit
03e37faea4
@ -3,7 +3,7 @@ class Locale
|
||||
end
|
||||
|
||||
LANGUAGE_REGEX = /(?:[a-z]{2,3})/ # ISO 639-1 or ISO 639-2
|
||||
REGION_REGEX = /(?:[A-Z]{2})/ # ISO 3166-1
|
||||
REGION_REGEX = /(?:[A-Z]{2}|\d{3})/ # ISO 3166-1 or UN M.49
|
||||
SCRIPT_REGEX = /(?:[A-Z][a-z]{3})/ # ISO 15924
|
||||
|
||||
LOCALE_REGEX = /\A((?:#{LANGUAGE_REGEX}|#{REGION_REGEX}|#{SCRIPT_REGEX})(?:\-|$)){1,3}\Z/
|
||||
|
@ -9,6 +9,10 @@ describe Locale do
|
||||
expect(described_class.parse("zh-CN-Hans")).to eql(described_class.new("zh", "CN", "Hans"))
|
||||
end
|
||||
|
||||
it "correctly parses a string with a UN M.49 region code" do
|
||||
expect(described_class.parse("es-419")).to eql(described_class.new("es", "419", nil))
|
||||
end
|
||||
|
||||
context "raises a ParserError when given" do
|
||||
it "an empty string" do
|
||||
expect { described_class.parse("") }.to raise_error(Locale::ParserError)
|
||||
|
Loading…
x
Reference in New Issue
Block a user