* Output Language sensitive Plugins

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
tatewise
Megastar
Posts: 28414
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Output Language sensitive Plugins

Post by tatewise »

Many plugins produce Result Sets or other displayable text.
The user can set the Tools > Preferences > International > Default Output Language to a Language Pack?
Perhaps the user has chosen German (DEU 1.1) so plugins should honour that and produce German output.

For example, my Improve Website or CD DVD HTML plugin employs English words, which look out of place in a German language website and ought to be translated.

However, there seems to be no standard method for a plugin to determine and use the chosen Language Pack.

There is a Windows Registry entry:
HKEY_CURRENT_USER\SOFTWARE\Calico Pie\Family Historian\2.0\Preferences\Output Language Id
For the example of German (DEU 1.1) that entry holds DEU 1.1

There is a folder with a matching name:
C:\ProgramData\Calico Pie\Family Historian\Lang\DEU 1.1 that holds the Language Pack files.
e.g.
lang_trans_misc.fh_lua defines language translation g_trans_misc Lua table entries such as:
g_trans_misc['Produced by Family Historian'] = 'Erstellt von Family Historian'
g_trans_misc['Sunday'] = 'Sonntag'
g_trans_misc['Monday'] = 'Montag'
g_trans_misc['Tuesday'] = 'Dienstag'

So a plugin could dig out the Windows Registry Output Language Id entry and load the lang_trans_misc.fh_lua file in order to use the g_trans_misc translation table.

However, does anyone know of a better way?
Last edited by ColeValleyGirl on 05 Nov 2021 16:52, edited 1 time in total.
Reason: Typo in title
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
tatewise
Megastar
Posts: 28414
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Output Language sensitive Plugins

Post by tatewise »

Since there seems to be no other way, this is what I have developed where getRegKey() uses Registry Key Read:

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[strText] or strText
end -- function StrTranslate
Note that g_trans_misc.Output_Language can be used in messages to user.
Text in the plugin is translated by calling StrTranslate("Text") that returns the translation or the original text.

Perhaps that code could become a Knowledge Base snippet?
Last edited by tatewise on 10 Nov 2021 11:20, edited 2 times in total.
Reason: Revise code snippet
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Output Language sensitive Plugins

Post by JoopvB »

Hi Mike,

Nice and certainly worth saving it as a Knowledge Base snippet!

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

Re: Output Language sensitive Plugins

Post by tatewise »

The Improve Website or CD DVD HTML plugin Version 3.2 Date 18 Nov 2021 is in the Plugin Store and uses the techniques described here to translate FH created web pages for the current Default Output Language.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Post Reply