Support geozone segments with non-Latin characters
The `parameterize` method uses the `I18n.transliterate` method, whose
documentation says:
```
I18n.transliterate("Ærøskøbing")
=> "AEroskobing"
I18n.transliterate("日本語")
=> "???"
```
That means we can't use it for dictionaries where characters don't have
a transliteration to the latin alphabet.
So we're changing the code in order to only transliterate characters
with a transliteration to the latin alphabet.
Note the first example ("Česká republika") already worked with the
previous code; the test has been added to make sure accented characters
are handled properly.
This commit is contained in:
@@ -84,6 +84,12 @@ class UserSegments
|
||||
end
|
||||
|
||||
def self.geozones
|
||||
Geozone.order(:name).map { |geozone| [geozone.name.parameterize.underscore, geozone] }.to_h
|
||||
Geozone.order(:name).map do |geozone|
|
||||
[geozone.name.gsub(/./) { |char| character_approximation(char) }.underscore.tr(" ", "_"), geozone]
|
||||
end.to_h
|
||||
end
|
||||
|
||||
def self.character_approximation(char)
|
||||
I18n::Backend::Transliterator::HashTransliterator::DEFAULT_APPROXIMATIONS[char] || char
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user