1 # SPDX-FileCopyrightText: 2013-2022 Blender Foundation
3 # 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 FRIBIDI_LIB
: StringProperty(
114 name
="Fribidi Library",
115 description
="The FriBidi C compiled library (.so under Linux, .dll under windows...), you’ll likely have "
116 "to edit it if you’re under Windows, e.g. using the one included in Blender libraries repository",
118 default
="libfribidi.so.0",
119 get
=lambda self
: self
._settings
.FRIBIDI_LIB
,
120 set=lambda self
, val
: setattr(self
._settings
, "FRIBIDI_LIB", val
),
123 SOURCE_DIR
: StringProperty(
125 description
="The Blender source root path",
128 get
=lambda self
: self
._settings
.SOURCE_DIR
,
129 set=lambda self
, val
: setattr(self
._settings
, "SOURCE_DIR", val
),
132 I18N_DIR
: StringProperty(
133 name
="Translation Root",
134 description
="The bf-translation repository",
137 get
=lambda self
: self
._settings
.I18N_DIR
,
138 set=lambda self
, val
: setattr(self
._settings
, "I18N_DIR", val
),
141 SPELL_CACHE
: StringProperty(
143 description
="A cache storing validated msgids, to avoid re-spellchecking them",
145 default
=os
.path
.join("/tmp", ".spell_cache"),
146 get
=lambda self
: self
._settings
.SPELL_CACHE
,
147 set=lambda self
, val
: setattr(self
._settings
, "SPELL_CACHE", val
),
150 PY_SYS_PATHS
: StringProperty(
152 description
="Additional paths to add to sys.path (';' separated)",
154 get
=lambda self
: self
._settings
.PY_SYS_PATHS
,
155 set=lambda self
, val
: setattr(self
._settings
, "PY_SYS_PATHS", val
),
158 persistent_data_path
: StringProperty(
159 name
="Persistent Data Path",
160 description
="The name of a json file storing those settings (unfortunately, Blender's system "
161 "does not work here)",
163 default
=os
.path
.join("ui_translate_settings.json"),
167 def draw(self
, context
):
169 layout
.label(text
="WARNING: preferences are lost when add-on is disabled, be sure to use \"Save Persistent\" "
170 "if you want to keep your settings!")
171 layout
.prop(self
, "WARN_MSGID_NOT_CAPITALIZED")
172 layout
.prop(self
, "FRIBIDI_LIB")
173 layout
.prop(self
, "SOURCE_DIR")
174 layout
.prop(self
, "I18N_DIR")
175 layout
.prop(self
, "SPELL_CACHE")
176 layout
.prop(self
, "PY_SYS_PATHS")
179 split
= layout
.split(factor
=0.75)
181 col
.prop(self
, "persistent_data_path")
183 row
.operator("ui.i18n_settings_save", text
="Save").filepath
= self
.persistent_data_path
184 row
.operator("ui.i18n_settings_load", text
="Load").filepath
= self
.persistent_data_path
186 col
.operator("ui.i18n_settings_save", text
="Save Persistent To...")
187 col
.operator("ui.i18n_settings_load", text
="Load Persistent From...")
191 UI_OT_i18n_settings_load
,
192 UI_OT_i18n_settings_save
,