Skip to content

Instantly share code, notes, and snippets.

@nutti
Last active August 29, 2015 14:20
Show Gist options
  • Save nutti/a3f7414ed824368195b5 to your computer and use it in GitHub Desktop.
Save nutti/a3f7414ed824368195b5 to your computer and use it in GitHub Desktop.
[Blender] Blenderスクリプトを多言語対応させる方法 ref: http://qiita.com/nutti/items/adcf4feb45135d649105
{locale: {(context, key): translated_str, ...}, ...}
translation_dict = {
"en_US" :
{("*", "Test: ") : "Test: %d"},
"ja_JP" :
{("*", "Test: ") : "てすと: %d"}
}
>>> bpy.app.translations.locale
'en_US'
bpy.app.translations.register(__name__, translation_dict)
bpy.app.translations.pgettext("Test: ")
bpy.app.translations.pgettext("Test: ") % (num)
bpy.app.translations.unregister(__name__)
import bpy
bl_info = {
"name" : "Translation Test",
"author" : "Nutti",
"version" : (0, 1),
"blender" : (2, 7, 0),
"location" : "UV > Translation Test",
"description" : "Translation Test",
"warning" : "",
"wiki_url" : "",
"tracker_url" : "",
"category" : "UV"
}
# 翻訳用辞書
translation_dict = {
"en_US" :
{("*", "Test: ") : "Test: %d"},
"ja_JP" :
{("*", "Test: ") : "てすと: %d"}
}
class TranslationTest(bpy.types.Operator):
bl_idname = "uv.translation_test"
bl_label = "Translation Test"
bl_description = "Translation Test"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
num = 50
# 翻訳結果を通知バーに表示
self.report({'INFO'}, bpy.app.translations.pgettext("Test: ") % (num))
return {'FINISHED'}
def menu_func(self, context):
self.layout.separator()
self.layout.operator(TranslationTest.bl_idname)
def register():
bpy.utils.register_module(__name__)
bpy.types.VIEW3D_MT_uv_map.append(menu_func)
bpy.app.translations.register(__name__, translation_dict) # 辞書の登録
def unregister():
bpy.app.translations.unregister(__name__) # 辞書の削除
bpy.utils.unregister_module(__name__)
bpy.types.VIEW3D_MT_uv_map.remove(menu_func)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment