13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/bisu/localizer.rb', line 13
def localize(text, language, locale, fallback_languages=[])
t = text
t = t.gsub("$specialKLanguage$", language)
t = t.gsub("$specialKLocale$", locale)
t = t.gsub("$specialKComment1$", "This file was automatically generated based on a translation template.")
t = t.gsub("$specialKComment2$", "Remember to CHANGE THE TEMPLATE and not this file!")
to_localize(t).map do |l|
if localized = localize_key(l[:key], [language] + fallback_languages)
localized = process(localized, l[:is_formatted_string])
l[:params].each do |param, value|
if localized.match("%{#{param}}")
localized = localized.gsub("%{#{param}}", value)
else
Logger.error("Parameter #{param} not found in translation for #{l[:key]} in #{language}")
end
end
unless t.gsub!(l[:match], localized)
Logger.warn("Could not find translation for #{l[:match]} in #{language}")
end
unless @type.eql?(:ror) || l[:ignore_params] == true
localized.scan(/%{[^}]+}/) { |match| Logger.error("Could not find translation param for #{match} for #{l[:key]} in #{language}") }
end
else
Logger.warn("Could not find translation for #{l[:match]} in #{language}")
end
end
t
end
|