From 989ea5d86230a8ce2f7050cdb3488888ffebda17 Mon Sep 17 00:00:00 2001 From: Kyzentun Date: Mon, 2 Feb 2015 09:19:51 -0700 Subject: [PATCH] Added script function for finding what needs to be translated. --- Docs/Changelog_sm5.txt | 12 ++++ .../Scripts/find_missing_lang_strings.lua | 64 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 Themes/_fallback/Scripts/find_missing_lang_strings.lua diff --git a/Docs/Changelog_sm5.txt b/Docs/Changelog_sm5.txt index 54d5565f51..cd12b3eda8 100644 --- a/Docs/Changelog_sm5.txt +++ b/Docs/Changelog_sm5.txt @@ -4,6 +4,18 @@ The StepMania 5 Changelog covers all post-sm-ssc changes. For a list of changes from StepMania 4 alpha 5 to sm-ssc v1.2.5, see Changelog_sm-ssc.txt. ________________________________________________________________________________ +2015/02/02 +---------- +* [Scripts] find_missing_strings_in_theme_translations function added to + _fallback scripts to assist translators in finding what needs to be + translated. If you need/want to run it on your them, write a piece of lua + like this: + find_missing_strings_in_theme_translations("_fallback", "en.ini") + The first arg is the folder name of the theme to look at. + The second arg is the name of the language that is fully translated. All + other languages will be compared to it to decide what is missing or unused. + [kyzentun] + 2015/01/31 ---------- * [EditMode] Want more lead in time before recording starts? diff --git a/Themes/_fallback/Scripts/find_missing_lang_strings.lua b/Themes/_fallback/Scripts/find_missing_lang_strings.lua new file mode 100644 index 0000000000..3d4584558e --- /dev/null +++ b/Themes/_fallback/Scripts/find_missing_lang_strings.lua @@ -0,0 +1,64 @@ +-- All other languages are compared to the master language to determine what is +-- missing and what is unused. +-- The list of missing strings for a language is saved to lang_missing.ini, +-- where lang is the name of the language. +-- The list of unused strings is saved to lang_unused.ini. + +function find_missing_strings_in_theme_translations(theme_name, master_name) + local lang_folder= "Themes/"..theme_name.."/Languages/" + local master_language= IniFile.ReadFile(lang_folder .. master_name) + local other_languages= {} + local language_names= FILEMAN:GetDirListing(lang_folder) + -- Load all languages. + for i, name in ipairs(language_names) do + if name ~= master_name and not name:find("missing") + and not name:find("unused") then + other_languages[#other_languages+1]= { + name= name, data= IniFile.ReadFile(lang_folder .. name)} + end + end + -- Find out what is missing from each language. + local missing_list= {} + local function find_missing_in_section(section_name, section) + local function add_str_to_missing(str_name, str_value) + for i, other in ipairs(other_languages) do + if not other.data[section_name] or + not other.data[section_name][str_name] then + if not missing_list[other.name] then + missing_list[other.name]= {} + end + if not missing_list[other.name][section_name] then + missing_list[other.name][section_name]= {} + end + missing_list[other.name][section_name][str_name]= str_value + end + end + end + foreach_ordered(section, add_str_to_missing) + end + foreach_ordered(master_language, find_missing_in_section) + local function save_missing_data(lang_name, data) + IniFile.WriteFile( + lang_folder .. lang_name:sub(1, -5) .. "_missing.ini", data) + end + foreach_ordered(missing_list, save_missing_data) + -- Find out what is extra in each language. + for i, other in ipairs(other_languages) do + local unused= {} + local function find_unused_in_section(section_name, section) + local function add_str_to_unused(str_name, str_value) + if not master_language[section_name] or + not master_language[section_name][str_name] then + if not unused[section_name] then + unused[section_name]= {} + end + unused[section_name][str_name]= str_value + end + end + foreach_ordered(section, add_str_to_unused) + end + foreach_ordered(other.data, find_unused_in_section) + IniFile.WriteFile( + lang_folder .. other.name:sub(1, -5) .. "_unused.ini", unused) + end +end