Last active
August 29, 2015 14:20
-
-
Save nutti/a3f7414ed824368195b5 to your computer and use it in GitHub Desktop.
[Blender] Blenderスクリプトを多言語対応させる方法 ref: http://qiita.com/nutti/items/adcf4feb45135d649105
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{locale: {(context, key): translated_str, ...}, ...} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
translation_dict = { | |
"en_US" : | |
{("*", "Test: ") : "Test: %d"}, | |
"ja_JP" : | |
{("*", "Test: ") : "てすと: %d"} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> bpy.app.translations.locale | |
'en_US' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bpy.app.translations.register(__name__, translation_dict) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bpy.app.translations.pgettext("Test: ") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bpy.app.translations.pgettext("Test: ") % (num) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bpy.app.translations.unregister(__name__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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