* Snippet: Translate Output Language

A place for completed suggestions/corrections.

Moderator: kb admin

Post Reply
User avatar
tatewise
Megastar
Posts: 24408
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Snippet: Translate Output Language

Post by tatewise » 10 Nov 2021 11:45

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
Last edited by tatewise on 11 Nov 2021 20:11, edited 1 time in total.
Reason: Revise code snippet
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
ColeValleyGirl
Megastar
Posts: 3688
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Snippet: Translate Output Language

Post by ColeValleyGirl » 28 Nov 2021 09:55

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?

User avatar
tatewise
Megastar
Posts: 24408
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Snippet: Translate Output Language

Post by tatewise » 28 Nov 2021 12:26

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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
ColeValleyGirl
Megastar
Posts: 3688
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Snippet: Translate Output Language

Post by ColeValleyGirl » 28 Nov 2021 12:33

OK. Maybe there should be a reference to the instructions for editing language packs, wherever those are.

User avatar
tatewise
Megastar
Posts: 24408
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Snippet: Translate Output Language

Post by tatewise » 28 Nov 2021 13:42

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'
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
ColeValleyGirl
Megastar
Posts: 3688
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Snippet: Translate Output Language

Post by ColeValleyGirl » 28 Nov 2021 13:55

Have a look at the wording now. OK?

User avatar
tatewise
Megastar
Posts: 24408
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Snippet: Translate Output Language

Post by tatewise » 28 Nov 2021 15:34

That looks good. :D
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Post Reply