1 # SPDX-License-Identifier: GPL-2.0-or-later
7 importlib
.reload(settings_i18n
)
10 from bpy
.types
import (
14 from bpy
.props
import (
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'}
33 filepath
: StringProperty(
35 description
="Path to the saved settings file",
38 filter_glob
: StringProperty(
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'}
49 return self
.execute(context
)
51 def execute(self
, context
):
52 if not (self
.filepath
and settings
):
54 settings
.load(self
.filepath
, reset
=True)
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'}
65 filepath
: StringProperty(
66 description
="Path to the saved settings file",
70 filter_glob
: StringProperty(
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'}
81 return self
.execute(context
)
83 def execute(self
, context
):
84 if not (self
.filepath
and settings
):
86 settings
.save(self
.filepath
)
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'}
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!)",
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",
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",
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(
132 description
="The Blender source root path",
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",
144 get
=lambda self
: self
._settings
.I18N_DIR
,
145 set=lambda self
, val
: setattr(self
._settings
, "I18N_DIR", val
),
148 SPELL_CACHE
: StringProperty(
150 description
="A cache storing validated msgids, to avoid re-spellchecking them",
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(
159 description
="Additional paths to add to sys.path (';' separated)",
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)",
170 default
=os
.path
.join("ui_translate_settings.json"),
174 def draw(self
, context
):
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")
187 split
= layout
.split(factor
=0.75)
189 col
.prop(self
, "persistent_data_path")
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
194 col
.operator("ui.i18n_settings_save", text
="Save Persistent To...")
195 col
.operator("ui.i18n_settings_load", text
="Load Persistent From...")
199 UI_OT_i18n_settings_load
,
200 UI_OT_i18n_settings_save
,