As I mentioned in some of the other threads …
…
Keep in mind the interpreter parser is compiled C while the LanguageHandler class’ parser is interpreted Ruby.
…
I’m not sure if I have posted an example, but basically I just create a “lang
” subfolder of my plugin folder, and populate it with .rb
scripts that use a naming syntax like “#{LANG}.rb
”, where the plugin constant LANG
is either a specific language the user has selected in my plugin’s options dialog (which can be even languages the SketchUp doesn’t even ship using,) or (upon first run) the string returned by Sketchup::get_locale()
.
In the main plugin file, I’d define some lang constants used by all languages:
# encoding: UTF-8
module Author::SomePlugin
KEY ||= Module.nesting.name[0].gsub('::','_') # qualified registry / plist key
LANGCODES ||= Hash[
:english,'en-US', :french,'fr', :italian,'it',
:german,'de', :spanish,'es', :japan,'ja',
:korean,'ko', :china,'zh-CN', :taiwan,'zh-TW',
:portbraz,'pt-BR', :dutch,'nl', :russian,'ru'
]
LANG ||= Sketchup.read_default(KEY,'lang')
if LANG.nil? # has not been set (1st run)
LANG = Sketchup::get_locale # set it
Sketchup.write_default(KEY,'lang',LANG) # store it
end
LANGFILE ||= File.join( File.dirname(__FILE__),"lang/#{LANG}.rb" )
load(LANGFILE) rescue load( File.join( File.dirname(__FILE__),'lang/en-US.rb' ))
end
Then the contents of the language ruby scripts for "lang/en-US.rb"
would be like:
# encoding: UTF-8
module Author::SomePlugin
OPTIONS_PROMPTS ||= {
:lang => 'Language',
:data => 'Data Path',
:save => 'Save Path:',
# etc., etc., ...
}
OPTIONS_ITEMS ||= {
:lang => LANGCODES.join('|'),
}
STATUSBAR ||= {
:tool1 => 'This tool does such and so forth',
:tool2 => 'This tool does more than any other'
# etc., etc., ...
}
# ETC., ETC., ...
end
Then I copy the english RB file a number of times and edit it and rename it for other languages.