glTF: fix typo
[blender-addons.git] / ui_translate / settings.py
bloba3f4c41f22ed7ae1b6040d4f05bb19121131e23c
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import os
5 if "bpy" in locals():
6 import importlib
7 importlib.reload(settings_i18n)
8 else:
9 import bpy
10 from bpy.types import (
11 Operator,
12 AddonPreferences,
14 from bpy.props import (
15 BoolProperty,
16 StringProperty,
18 from bl_i18n_utils import settings as settings_i18n
21 settings = settings_i18n.I18nSettings()
24 # Operators ###################################################################
26 class UI_OT_i18n_settings_load(Operator):
27 """Load translations' settings from a persistent JSon file"""
28 bl_idname = "ui.i18n_settings_load"
29 bl_label = "I18n Load Settings"
30 bl_option = {'REGISTER'}
32 # Operator Arguments
33 filepath: StringProperty(
34 subtype='FILE_PATH',
35 description="Path to the saved settings file",
38 filter_glob: StringProperty(
39 default="*.json",
40 options={'HIDDEN'}
42 # /End Operator Arguments
44 def invoke(self, context, event):
45 if not self.properties.is_property_set("filepath"):
46 context.window_manager.fileselect_add(self)
47 return {'RUNNING_MODAL'}
48 else:
49 return self.execute(context)
51 def execute(self, context):
52 if not (self.filepath and settings):
53 return {'CANCELLED'}
54 settings.load(self.filepath, reset=True)
55 return {'FINISHED'}
58 class UI_OT_i18n_settings_save(Operator):
59 """Save translations' settings in a persistent JSon file"""
60 bl_idname = "ui.i18n_settings_save"
61 bl_label = "I18n Save Settings"
62 bl_option = {'REGISTER'}
64 # Operator Arguments
65 filepath: StringProperty(
66 description="Path to the saved settings file",
67 subtype='FILE_PATH',
70 filter_glob: StringProperty(
71 default="*.json",
72 options={'HIDDEN'},
74 # /End Operator Arguments
76 def invoke(self, context, event):
77 if not self.properties.is_property_set("filepath"):
78 context.window_manager.fileselect_add(self)
79 return {'RUNNING_MODAL'}
80 else:
81 return self.execute(context)
83 def execute(self, context):
84 if not (self.filepath and settings):
85 return {'CANCELLED'}
86 settings.save(self.filepath)
87 return {'FINISHED'}
90 # Addon Preferences ###########################################################
92 def _setattr(self, name, val):
93 print(self, name, val)
94 setattr(self, name, val)
97 class UI_AP_i18n_settings(AddonPreferences):
98 bl_idname = __name__.split(".")[0] # We want "top" module name!
99 bl_option = {'REGISTER'}
101 _settings = settings
103 WARN_MSGID_NOT_CAPITALIZED: BoolProperty(
104 name="Warn Msgid Not Capitalized",
105 description="Warn about messages not starting by a capitalized letter (with a few allowed exceptions!)",
106 default=True,
107 get=lambda self: self._settings.WARN_MSGID_NOT_CAPITALIZED,
108 set=lambda self, val: _setattr(self._settings, "WARN_MSGID_NOT_CAPITALIZED", val),
111 GETTEXT_MSGFMT_EXECUTABLE: StringProperty(
112 name="Gettext 'msgfmt' executable",
113 description="The gettext msgfmt 'compiler'. You’ll likely have to edit it if you’re under Windows",
114 subtype='FILE_PATH',
115 default="msgfmt",
116 get=lambda self: self._settings.GETTEXT_MSGFMT_EXECUTABLE,
117 set=lambda self, val: setattr(self._settings, "GETTEXT_MSGFMT_EXECUTABLE", val),
120 FRIBIDI_LIB: StringProperty(
121 name="Fribidi Library",
122 description="The FriBidi C compiled library (.so under Linux, .dll under windows...), you’ll likely have "
123 "to edit it if you’re under Windows, e.g. using the one included in svn's libraries repository",
124 subtype='FILE_PATH',
125 default="libfribidi.so.0",
126 get=lambda self: self._settings.FRIBIDI_LIB,
127 set=lambda self, val: setattr(self._settings, "FRIBIDI_LIB", val),
130 SOURCE_DIR: StringProperty(
131 name="Source Root",
132 description="The Blender source root path",
133 subtype='FILE_PATH',
134 default="blender",
135 get=lambda self: self._settings.SOURCE_DIR,
136 set=lambda self, val: setattr(self._settings, "SOURCE_DIR", val),
139 I18N_DIR: StringProperty(
140 name="Translation Root",
141 description="The bf-translation repository",
142 subtype='FILE_PATH',
143 default="i18n",
144 get=lambda self: self._settings.I18N_DIR,
145 set=lambda self, val: setattr(self._settings, "I18N_DIR", val),
148 SPELL_CACHE: StringProperty(
149 name="Spell Cache",
150 description="A cache storing validated msgids, to avoid re-spellchecking them",
151 subtype='FILE_PATH',
152 default=os.path.join("/tmp", ".spell_cache"),
153 get=lambda self: self._settings.SPELL_CACHE,
154 set=lambda self, val: setattr(self._settings, "SPELL_CACHE", val),
157 PY_SYS_PATHS: StringProperty(
158 name="Import Paths",
159 description="Additional paths to add to sys.path (';' separated)",
160 default="",
161 get=lambda self: self._settings.PY_SYS_PATHS,
162 set=lambda self, val: setattr(self._settings, "PY_SYS_PATHS", val),
165 persistent_data_path: StringProperty(
166 name="Persistent Data Path",
167 description="The name of a json file storing those settings (unfortunately, Blender's system "
168 "does not work here)",
169 subtype='FILE_PATH',
170 default=os.path.join("ui_translate_settings.json"),
172 _is_init = False
174 def draw(self, context):
175 layout = self.layout
176 layout.label(text="WARNING: preferences are lost when add-on is disabled, be sure to use \"Save Persistent\" "
177 "if you want to keep your settings!")
178 layout.prop(self, "WARN_MSGID_NOT_CAPITALIZED")
179 layout.prop(self, "GETTEXT_MSGFMT_EXECUTABLE")
180 layout.prop(self, "FRIBIDI_LIB")
181 layout.prop(self, "SOURCE_DIR")
182 layout.prop(self, "I18N_DIR")
183 layout.prop(self, "SPELL_CACHE")
184 layout.prop(self, "PY_SYS_PATHS")
186 layout.separator()
187 split = layout.split(factor=0.75)
188 col = split.column()
189 col.prop(self, "persistent_data_path")
190 row = col.row()
191 row.operator("ui.i18n_settings_save", text="Save").filepath = self.persistent_data_path
192 row.operator("ui.i18n_settings_load", text="Load").filepath = self.persistent_data_path
193 col = split.column()
194 col.operator("ui.i18n_settings_save", text="Save Persistent To...")
195 col.operator("ui.i18n_settings_load", text="Load Persistent From...")
198 classes = (
199 UI_OT_i18n_settings_load,
200 UI_OT_i18n_settings_save,
201 UI_AP_i18n_settings,