Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ version: 0.1.0
authors:
- Arnaud Fernandés <arnaud.fernandes@laposte.net>

crystal: 0.24.2
crystal: 0.25.0

license: MIT
16 changes: 9 additions & 7 deletions src/i18n/backend/yaml.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module I18n
getter available_locales
property translations

@translations = Hash(String, Hash(String, YAML::Type)).new
@translations = Hash(String, Hash(String, YAML::Any)).new

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think YAML::Any should be replaced with YAML::Any::Type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, no. YAML.parse returns an YAML::Any.

@available_locales = Array(String).new

macro embed(dirs)
Expand All @@ -30,8 +30,8 @@ module I18n
lang_data = load_file(file)
next if lang_data.raw.nil?

@translations[lang] ||= {} of String => YAML::Type
@translations[lang].merge!(self.class.normalize(lang_data.as_h))
@translations[lang] ||= {} of String => YAML::Any
@translations[lang].merge!(self.class.normalize(lang_data))
@available_locales << lang unless @available_locales.includes?(lang)
end
else
Expand All @@ -54,7 +54,7 @@ module I18n
)
end

return tr[iter].to_s if tr && iter && tr.is_a? Array(YAML::Type)
return tr[iter].to_s if tr && iter && tr.is_a?(YAML::Any)

tr = tr.to_s
tr = tr.sub(/\%{count}/, count) if count
Expand Down Expand Up @@ -182,16 +182,18 @@ module I18n
end
end

def self.normalize(data : Hash, path : String = "", final = Hash(String, YAML::Type).new)
data.keys.each do |k|
def self.normalize(data : YAML::Any, path : String = "", final = Hash(String, YAML::Any).new)
data.as_h.keys.each do |k|
newp = path.size == 0 ? k.to_s : path + "." + k.to_s
newdata = data[k]
if newdata.is_a?(Hash)

if newdata.as_h?
normalize(newdata, newp, final)
else
final[newp] = newdata
end
end

final
end
end
Expand Down