X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/ef7f3d800cbdd49b692df10d312e5fd880e2e938..2a44ff581f4c547a3637ea52567a3398b1d8bfe0:/script/locale/po2yaml diff --git a/script/locale/po2yaml b/script/locale/po2yaml index ea78ce2c6..69278ea69 100755 --- a/script/locale/po2yaml +++ b/script/locale/po2yaml @@ -11,9 +11,8 @@ def add_translation(hash, keys, value) if keys.empty? hash[key] = value else - unless hash.key? key - hash[key] = {} - end + hash[key] ||= {} + add_translation(hash[key], keys, value) end hash @@ -22,20 +21,20 @@ end def po2hash(f) trs = {} path = [] - msgstr = '' + msgstr = "" f.each_line do |line| line.strip! if line[0..8] == 'msgctxt "' - path = line[9..-2].split(':') + path = line[9..-2].split(":") elsif line[0..7] == 'msgstr "' msgstr = line[8..-2] end - if !path.empty? && !msgstr.empty? - add_translation(trs, path, msgstr) - path = [] - msgstr = '' - end + next if path.empty? || msgstr.empty? + + add_translation(trs, path, msgstr) + path = [] + msgstr = "" end trs end @@ -43,7 +42,7 @@ end filename = ARGV[0] pofile = File.open(filename, "r") -langcode = File.basename(filename, '.po') +langcode = File.basename(filename, ".po") tr = { langcode => po2hash(pofile) }