mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Parse available language string more relaxed
Splitting the string with any whitespace makes it more likely the code knows what the human meant. It also makes `strip` obsolete, since there can't be any whitespace within the splitted strings.
This commit is contained in:
@@ -4,7 +4,7 @@ module OpenFoodNetwork
|
||||
# See: config/application.yml
|
||||
class I18nConfig
|
||||
def self.selectable_locales
|
||||
ENV["AVAILABLE_LOCALES"].andand.split(/[\s,]/).andand.map(&:strip) || []
|
||||
ENV["AVAILABLE_LOCALES"].andand.split(/[\s,]+/) || []
|
||||
end
|
||||
|
||||
def self.available_locales
|
||||
|
||||
@@ -77,17 +77,15 @@ module OpenFoodNetwork
|
||||
context "with human syntax" do
|
||||
before do
|
||||
allow(ENV).to receive(:[]).with("LOCALE").and_return("es")
|
||||
allow(ENV).to receive(:[]).with("AVAILABLE_LOCALES").and_return("es, fr")
|
||||
allow(ENV).to receive(:[]).with("AVAILABLE_LOCALES").and_return("es, fr ,, ,de")
|
||||
end
|
||||
|
||||
xit "provides the default selectable locales" do
|
||||
# current: expect(I18nConfig.selectable_locales).to eq ["es", "", "fr"]
|
||||
expect(I18nConfig.selectable_locales).to eq ["es", "fr"]
|
||||
it "provides the default selectable locales" do
|
||||
expect(I18nConfig.selectable_locales).to eq ["es", "fr", "de"]
|
||||
end
|
||||
|
||||
xit "provides the default available locales" do
|
||||
# current: expect(I18nConfig.available_locales).to eq ["es", "", "fr", "en"]
|
||||
expect(I18nConfig.available_locales).to eq ["es", "fr", "en"]
|
||||
it "provides the default available locales" do
|
||||
expect(I18nConfig.available_locales).to eq ["es", "fr", "de", "en"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user