1 # SPDX-License-Identifier: GPL-2.0-or-later
9 importlib
.reload(settings_i18n
)
12 from bpy
.types
import (
16 from bpy
.props
import (
20 from bl_i18n_utils
import settings
as settings_i18n
23 settings
= settings_i18n
.I18nSettings()
26 # Operators ###################################################################
28 class UI_OT_i18n_settings_load(Operator
):
29 """Load translations' settings from a persistent JSon file"""
30 bl_idname
= "ui.i18n_settings_load"
31 bl_label
= "I18n Load Settings"
32 bl_option
= {'REGISTER'}
35 filepath
: StringProperty(
37 description
="Path to the saved settings file",
40 filter_glob
: StringProperty(
44 # /End Operator Arguments
46 def invoke(self
, context
, event
):
47 if not self
.properties
.is_property_set("filepath"):
48 context
.window_manager
.fileselect_add(self
)
49 return {'RUNNING_MODAL'}
51 return self
.execute(context
)
53 def execute(self
, context
):
54 if not (self
.filepath
and settings
):
56 settings
.load(self
.filepath
, reset
=True)
60 class UI_OT_i18n_settings_save(Operator
):
61 """Save translations' settings in a persistent JSon file"""
62 bl_idname
= "ui.i18n_settings_save"
63 bl_label
= "I18n Save Settings"
64 bl_option
= {'REGISTER'}
67 filepath
: StringProperty(
68 description
="Path to the saved settings file",
72 filter_glob
: StringProperty(
76 # /End Operator Arguments
78 def invoke(self
, context
, event
):
79 if not self
.properties
.is_property_set("filepath"):
80 context
.window_manager
.fileselect_add(self
)
81 return {'RUNNING_MODAL'}
83 return self
.execute(context
)
85 def execute(self
, context
):
86 if not (self
.filepath
and settings
):
88 settings
.save(self
.filepath
)
92 # Addon Preferences ###########################################################
94 def _setattr(self
, name
, val
):
95 print(self
, name
, val
)
96 setattr(self
, name
, val
)
99 class UI_AP_i18n_settings(AddonPreferences
):
100 bl_idname
= __name__
.split(".")[0] # We want "top" module name!
101 bl_option
= {'REGISTER'}
105 WARN_MSGID_NOT_CAPITALIZED
: BoolProperty(
106 name
="Warn Msgid Not Capitalized",
107 description
="Warn about messages not starting by a capitalized letter (with a few allowed exceptions!)",
109 get
=lambda self
: self
._settings
.WARN_MSGID_NOT_CAPITALIZED
,
110 set=lambda self
, val
: _setattr(self
._settings
, "WARN_MSGID_NOT_CAPITALIZED", val
),
113 GETTEXT_MSGFMT_EXECUTABLE
: StringProperty(
114 name
="Gettext 'msgfmt' executable",
115 description
="The gettext msgfmt 'compiler'. You’ll likely have to edit it if you’re under Windows",
118 get
=lambda self
: self
._settings
.GETTEXT_MSGFMT_EXECUTABLE
,
119 set=lambda self
, val
: setattr(self
._settings
, "GETTEXT_MSGFMT_EXECUTABLE", val
),
122 FRIBIDI_LIB
: StringProperty(
123 name
="Fribidi Library",
124 description
="The FriBidi C compiled library (.so under Linux, .dll under windows...), you’ll likely have "
125 "to edit it if you’re under Windows, e.g. using the one included in svn's libraries repository",
127 default
="libfribidi.so.0",
128 get
=lambda self
: self
._settings
.FRIBIDI_LIB
,
129 set=lambda self
, val
: setattr(self
._settings
, "FRIBIDI_LIB", val
),
132 SOURCE_DIR
: StringProperty(
134 description
="The Blender source root path",
137 get
=lambda self
: self
._settings
.SOURCE_DIR
,
138 set=lambda self
, val
: setattr(self
._settings
, "SOURCE_DIR", val
),
141 I18N_DIR
: StringProperty(
142 name
="Translation Root",
143 description
="The bf-translation repository",
146 get
=lambda self
: self
._settings
.I18N_DIR
,
147 set=lambda self
, val
: setattr(self
._settings
, "I18N_DIR", val
),
150 SPELL_CACHE
: StringProperty(
152 description
="A cache storing validated msgids, to avoid re-spellchecking them",
154 default
=os
.path
.join("/tmp", ".spell_cache"),
155 get
=lambda self
: self
._settings
.SPELL_CACHE
,
156 set=lambda self
, val
: setattr(self
._settings
, "SPELL_CACHE", val
),
159 PY_SYS_PATHS
: StringProperty(
161 description
="Additional paths to add to sys.path (';' separated)",
163 get
=lambda self
: self
._settings
.PY_SYS_PATHS
,
164 set=lambda self
, val
: setattr(self
._settings
, "PY_SYS_PATHS", val
),
167 persistent_data_path
: StringProperty(
168 name
="Persistent Data Path",
169 description
="The name of a json file storing those settings (unfortunately, Blender's system "
170 "does not work here)",
172 default
=os
.path
.join("ui_translate_settings.json"),
176 def draw(self
, context
):
178 layout
.label(text
="WARNING: preferences are lost when add-on is disabled, be sure to use \"Save Persistent\" "
179 "if you want to keep your settings!")
180 layout
.prop(self
, "WARN_MSGID_NOT_CAPITALIZED")
181 layout
.prop(self
, "GETTEXT_MSGFMT_EXECUTABLE")
182 layout
.prop(self
, "FRIBIDI_LIB")
183 layout
.prop(self
, "SOURCE_DIR")
184 layout
.prop(self
, "I18N_DIR")
185 layout
.prop(self
, "SPELL_CACHE")
186 layout
.prop(self
, "PY_SYS_PATHS")
189 split
= layout
.split(factor
=0.75)
191 col
.prop(self
, "persistent_data_path")
193 row
.operator("ui.i18n_settings_save", text
="Save").filepath
= self
.persistent_data_path
194 row
.operator("ui.i18n_settings_load", text
="Load").filepath
= self
.persistent_data_path
196 col
.operator("ui.i18n_settings_save", text
="Save Persistent To...")
197 col
.operator("ui.i18n_settings_load", text
="Load Persistent From...")
201 UI_OT_i18n_settings_load
,
202 UI_OT_i18n_settings_save
,