Page 1 of 1

Snippet: Translate Output Language

Posted: 10 Nov 2021 11:45
by tatewise
Please add this Plugin Code Snippet to https://fhug.org.uk/kb/snippets/.

Translate Output Language
FH versions: V7 Category: Strings, User Interface

This allows the Tools > Preferences > International > Default Output Language to be determined and the associated Language Pack used to translate words and phrases into that language.

The Language Pack Miscellaneous Translation Table may need editing to add the required words and phrases.

The translated text can be applied to published documents in a similar way to Reports, and that is most relevant to Report type plugins and plugins that manage web pages.

Requires: Registry Key Read

Code

Code: Select all

g_trans_misc = { Output_Language = ""; }	-- Create global Language Pack translation table
if fhGetAppVersion() > 6 then
  local strLang = getRegKey("HKCU\\SOFTWARE\\Calico Pie\\Family Historian\\2.0\\Preferences\\Output Language Id")
  if #strLang > 2 then		-- Load the miscellaneous translations for chosen Language Pack
    local strPack = fhGetContextInfo("CI_APP_DATA_FOLDER").."\\Lang\\"..strLang.."\\lang_trans_misc.fh_lua"
    dofile(strPack)
    g_trans_misc.Output_Language = " for Output Language "..strLang
  else
    g_trans_misc.Output_Language = " for English"
  end
end

function StrTranslate(strText)	-- Translate text to current output language 
    return g_trans_misc["~CASE:"..strText] or g_trans_misc[strText] or strText
end -- function StrTranslate
Usage

Note that g_trans_misc.Output_Language can be used in messages to the user.

Text in the plugin is translated by calling StrTranslate("any text") that returns the translation, or the original text when no translation is available. If necessary, a special CASE can be employed to distinguish different translations.

Related Content

1. Registry Key Read

Re: Snippet: Translate Output Language

Posted: 28 Nov 2021 09:55
by ColeValleyGirl
Mike, I've added this snippet, but am a little bemused by:
The Language Pack Miscellaneous Translation Table may need editing to add the required words and phrases.
Are you saying the plugin author should also edit the language pack?

Re: Snippet: Translate Output Language

Posted: 28 Nov 2021 12:26
by tatewise
The plugin author could edit the Language Packs, but it is more likely that the Plugin Help & Advice would advise the users what words and phrases need adding to Language Packs they intend to use. See https://pluginstore.family-historian.co ... anslations.

Re: Snippet: Translate Output Language

Posted: 28 Nov 2021 12:33
by ColeValleyGirl
OK. Maybe there should be a reference to the instructions for editing language packs, wherever those are.

Re: Snippet: Translate Output Language

Posted: 28 Nov 2021 13:42
by tatewise
Like there are in https://pluginstore.family-historian.co ... anslations and in the FH v7 Help page How to Create a Language Pack: https://www.family-historian.co.uk/help ... epack.html under 'Supplying all necessary translations for language pack translation tables'

Re: Snippet: Translate Output Language

Posted: 28 Nov 2021 13:55
by ColeValleyGirl
Have a look at the wording now. OK?

Re: Snippet: Translate Output Language

Posted: 28 Nov 2021 15:34
by tatewise
That looks good. :D