I’ve managed to import my translations into localization table and adjust them for SmartFormatter.
How can I quickly check all translations as ‘smart’ ?
What’s the reason for having ‘smart’ setting on each translation instead on the whole row or even whole table ? Are there situations where it is helpful?
Hmm. We don’t really have an alternative than just setting the IsSmart flag for each language.
This can also be done through a script to speed things up.
You bring up an interesting point though, maybe we don’t need to set it for every language, setting it per entry is probably enough. I can’t actually think of an example of where you may only want smart on some now.
Ill make a note look into it with the UX team.
Thanks, for the clue. I managed to write one.
Although I had problems with saving… so there might be some bugs in it.
It eventually worked after I clicked on File -> Save Project and reopened Localization Tables window.
using UnityEditor;
using UnityEditor.Localization;
using UnityEngine;
...
var tableCollectionName = "Table_Collection";
var tableCollection = LocalizationEditorSettings.GetStringTableCollection(tableCollectionName);
foreach (var table in tableCollection.StringTables)
{
foreach (var element in table)
{
var entry = element.Value;
entry.IsSmart = true;
}
EditorUtility.SetDirty(table);
}
EditorUtility.SetDirty(tableCollection);
Do you mean the changes were not saved or that the file was not being written?
When you mark an asset dirty it does not save the file, just tells Unity that its changed so the next time it flushes to disk for a save it will write the file out.
The problem is that I’m not able to give a solid repro.
I’ve created a smaller project and uploaded there a lot of translations.
My observations:
files got modified everytime - that’s seems nice
once ‘localization tables’ window updated ok after running a script and saving the project
once I needed to reimport a folder with localization tables to force ‘localization tables’ window to update
another time the table collection lost connection to tables (they become loose)
and reimport didn’t help
but restarting Unity did help
I’ve not yet observed a situation from my main project, where after running a script ‘localization tables’ window was updated, but only partially (only some columns were updated)
Shall I report a bug with my above observations and this small project ?
Here you have my editor script from this smaller project:
FixLocalizations() function sets smart to true for all translations. FixLocalizations2() function is the same but sets smart to false.
I was playing with both of them alternately.
using UnityEditor;
using UnityEditor.Localization;
using UnityEngine;
public class LocalizationUtils : MonoBehaviour
{
[MenuItem("Dev/Fix Localizations")]
static void FixLocalizations()
{
// Mark all localizations as smart
var tableCollectionName = "Strings";
var tableCollection = LocalizationEditorSettings.GetStringTableCollection(tableCollectionName);
foreach (var table in tableCollection.StringTables)
{
foreach (var element in table)
{
var entry = element.Value;
entry.IsSmart = true;
}
EditorUtility.SetDirty(table);
}
EditorUtility.SetDirty(tableCollection);
}
[MenuItem("Dev/Fix Localizations 2")]
static void FixLocalizations2()
{
// Mark all localizations as not smart
var tableCollectionName = "Strings";
var tableCollection = LocalizationEditorSettings.GetStringTableCollection(tableCollectionName);
foreach (var table in tableCollection.StringTables)
{
foreach (var element in table)
{
var entry = element.Value;
entry.IsSmart = false;
}
EditorUtility.SetDirty(table);
}
EditorUtility.SetDirty(tableCollection);
}
}
Ok I think I know the issue.
Setting IsSmart makes changes to metadata inside of SharedTableData. So you also need to set that dirty.
You don’t need to set the collection dirty.
Do this where you set the collection dirty instead
I would like to avoid sharing the whole project,
but I was able to extract only the localization part.
It is enough to repro this ‘partial update’ problem at least on my side.
Shall I file this as a bug ? Will you be able to find it ?