# HG changeset patch # User jbe # Date 1615132739 -3600 # Node ID 2c31275322dba132d8a6065a76f8569236eaa04e # Parent 328f120924a2ae81fe306ccb95a8e0248fe16afc Allow inheritance in translation tables using __parent diff -r 328f120924a2 -r 2c31275322db framework/bin/langtool.lua --- a/framework/bin/langtool.lua Fri Feb 05 15:51:39 2021 +0100 +++ b/framework/bin/langtool.lua Sun Mar 07 16:58:59 2021 +0100 @@ -123,9 +123,7 @@ end local function update_translation(key, value) - if #directories > 0 then - if translations[key] ~= nil then translations[key] = value end - else + if translations[key] ~= nil or #directories == 0 or key == "__parent" then translations[key] = value end end diff -r 328f120924a2 -r 2c31275322db framework/env/__init.lua --- a/framework/env/__init.lua Fri Feb 05 15:51:39 2021 +0100 +++ b/framework/env/__init.lua Sun Mar 07 16:58:59 2021 +0100 @@ -13,6 +13,9 @@ Hint: Lua's syntax rules allow to write _"text" as a shortcut for _("text"), or _'text' instead of _('text') respectivly. +Translation files are located in the "locale" directory of the application and must have a name following the schema "translations.LANG.lua", where LANG is the language code set with locale.set{lang = ...}. +The special string "__parent" in the translation file may point to a different language code of which all translations are inherited from. + --]]-- function _G._(text, replacements) diff -r 328f120924a2 -r 2c31275322db framework/env/locale/_get_translation_table.lua --- a/framework/env/locale/_get_translation_table.lua Fri Feb 05 15:51:39 2021 +0100 +++ b/framework/env/locale/_get_translation_table.lua Sun Mar 07 16:58:59 2021 +0100 @@ -17,6 +17,15 @@ if type(translation_table) ~= "table" then error("Translation file did not return a table.") end + local parent_code = translation_table["__parent"] + if parent_code then + local parent_table = locale._get_translation_table(parent_code) + for key, value in pairs(parent_table) do + if translation_table[key] == nil then + translation_table[key] = value + end + end + end locale._translation_tables[language_code] = translation_table return translation_table else