40 LocalizationEditor stringEditor = Workbench.GetModule(LocalizationEditor);
53 WorldEditorAPI worldEditorAPI = ((WorldEditor)Workbench.GetModule(WorldEditor)).GetApi();
54 if (!worldEditorAPI.CreateObjectArrayVariableMember(stringTable, null,
"Items",
"CustomStringTableItem",
index))
59 item = items.Get(
index);
66 Workbench.GetUserName(userName);
68 stringEditor.ModifyProperty(item, item.GetVarIndex(
"Id"),
id);
69 stringEditor.ModifyProperty(item, item.GetVarIndex(
"Target_en_us"), text);
70 stringEditor.ModifyProperty(item, item.GetVarIndex(
"SourceFile"),
m_sFile);
71 stringEditor.ModifyProperty(item, item.GetVarIndex(
"Modified"), Workbench.GetPackedUtcTime().ToString());
72 stringEditor.ModifyProperty(item, item.GetVarIndex(
"Author"), userName);
73 stringEditor.ModifyProperty(item, item.GetVarIndex(
"LastChanged"), userName);
81 if (text == existingText)
83 Print(
string.Format(
"Item already localized, but its text is the same.\n ",
id, existingText),
LogLevel.WARNING);
87 Print(
string.Format(
"%1%2 = \"%3\"\n Item already localized, and its text differs! Localized text will be used!\n ",
LOCALIZED_PREFIX,
id, existingText),
LogLevel.ERROR);
110 for (
int v = 0, varCount = item.GetNumVars(); v < varCount; v++)
112 varName = item.GetVarName(v);
113 if (!itemTemplate.IsVariableSet(varName))
116 switch (item.GetDataVarType(v))
121 itemTemplate.Get(varName, value);
122 stringEditor.ModifyProperty(item, v, value);
128 itemTemplate.Get(varName, value);
129 stringEditor.ModifyProperty(item, v, value.ToString());
135 itemTemplate.Get(varName, value);
136 stringEditor.ModifyProperty(item, v, value.ToString());
141 array<string> valueInput;
142 itemTemplate.Get(varName, valueInput);
144 foreach (
int i,
string entry : valueInput)
149 valueOutput +=
string.ToString(entry);
152 stringEditor.ModifyProperty(item, v, valueOutput);
157 array<int> valueInput;
158 itemTemplate.Get(varName, valueInput);
160 foreach (
int i,
int entry : valueInput)
165 valueOutput += entry.ToString();
168 stringEditor.ModifyProperty(item, v, valueOutput);
173 array<bool> valueInput;
174 itemTemplate.Get(varName, valueInput);
176 foreach (
int i,
bool entry : valueInput)
181 valueOutput += entry.ToString();
183 stringEditor.ModifyProperty(item, v, valueOutput);
188 Print(
string.Format(
"Cannot copy variable '%1' from template, it has unsupported type %2!", varName,
typename.EnumToString(
DataVarType, item.GetDataVarType(v))),
LogLevel.ERROR);
204 if (!objects.IsEmpty())
206 string containerName;
209 container.Get(
"Name", containerName);
213 containerName = container.GetName();
214 if (containerName.IsEmpty())
215 containerName = container.GetClassName();
217 path +=
" > " + containerName;
220 array<BaseContainer> objectsCopy = {};
221 objectsCopy.Copy(objects);
222 objectsCopy.InsertAt(container, 0);
224 array<int> indexesCopy = {};
225 indexesCopy.Copy(indexes);
226 indexesCopy.InsertAt(
index, 0);
229 string varName,
id, text;
231 for (
int v = 0, varCount = container.GetNumVars(); v < varCount; v++)
233 varName = container.GetVarName(v);
236 if (!container.IsVariableSetDirectly(varName))
239 if (container.IsType(varName,
string) && container.Get(varName, text))
253 if (rule.Evaluate(
m_sFileName, varName, objectsCopy))
255 indexesCopy.Set(indexesCopy.Count() - 1,
index);
256 id = rule.GetID(
m_sFileName, varName, objectsCopy, indexesCopy);
265 rule.Localize(
m_sFileName, varName, objectsCopy,
id, text);
275 string uiWidget = container.GetUIWidget(v);
276 if (
m_bLogOnly && !found && (uiWidget ==
"localeeditbox" || uiWidget ==
"editboxWithButton"))
281 Print(
string.Format(
"No rule found for: %1 = '%2'\n\n", varName, text),
LogLevel.WARNING);
300 for (
int l = 0, listCount = list.Count(); l < listCount; l++)
302 ProcessContainer(list.Get(l), foundCount, objectsCopy, indexesCopy,
path +
string.Format(
" > %1[%2]", varName, l), index2);
311 for (
int e = 0, count = container.GetNumChildren(); e < count; e++)
327 if (stringTableOverride)
333 if (!Workbench.OpenModule(LocalizationEditor))
336 LocalizationEditor stringEditor = Workbench.GetModule(LocalizationEditor);
348 string itemId, itemText;
349 int itemsCount = items.Count();
350 for (
int i = 0; i < itemsCount; i++)
353 item.Get(
"Id", itemId);
354 item.Get(
"Target_en_us", itemText);
355 m_mIDs.Insert(itemId, itemText);
360 if (!Workbench.OpenModule(WorldEditor))
363 stringEditor.BeginModify(
"Automatic localization");
370 m_aRuleSources.Insert(rulesSource.Get(r).GetObject(
"m_ItemTemplate"));
375 array<ResourceName> selection = {};
376 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
377 resourceManager.GetResourceBrowserSelection(selection.Insert,
true);
378 WBProgressDialog progress =
new WBProgressDialog(
"Processing...", resourceManager);
381 int foundCount, foundCountPrev;
382 int selectionCount = selection.Count();
387 for (
int i = 0; i < selectionCount; i++)
389 progress.SetProgress(i / selectionCount);
394 if (!resource || !resource.IsValid())
397 baseResource = resource.GetResource();
401 container = baseResource.ToBaseContainer();
405 foundCountPrev = foundCount;
408 array<BaseContainer> objects = {};
409 array<int> indexes = {};
412 if (!
m_bLogOnly && foundCount != foundCountPrev)
420 stringEditor.EndModify();
426 array<int> newIds = {};
427 for (
int i = itemsCount, itemsCountNew = items.Count(); i <= itemsCountNew; i++)
431 stringEditor.AddUserFilter(newIds,
"New strings");
441 Print(
string.Format(
"%1 file(s) processed, %2 unlocalized string(s) found\n Logging only, no files were modified.", selectionCount, foundCount), logLevel);
445 Print(
string.Format(
"%1 file(s) processed, %2 string(s) localized", selectionCount, foundCount),
LogLevel.DEBUG);
461 if (!configResource.IsValid())
463 Print(
string.Format(
"Cannot load config '%1'!", configPath),
LogLevel.WARNING);
468 if (!configContainer)
471 BaseContainer configBase = configContainer.ToBaseContainer();
477 Print(
string.Format(
"Config '%1' is of type '%2', must be 'LocParserManager'!", configPath, configBase.GetClassName()),
LogLevel.WARNING);
483 manager.
Run(configBase, logOnly, stringTableOverride, prefixOverride);
485 Print(
string.Format(
"Unknown error when creating instance of config '%1'!", configPath),
LogLevel.WARNING);