Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [1.3.3] - 2026-10-28

### Added
- **Silently On Settings Change**: regenerate without asking when a setting that changes the generated code is
edited. Off by default.
- **On Metadata Edit**: regenerate on every edit of the **Smart Parameter Types** metadata. Off by default.

### Changed
- Editing **Smart Parameter Types** metadata no longer regenerates on every click; the code regenerates when the
table is saved.
- Every setting that changes the generated code (namespace, output folder, table kinds, members, naming, `.asmdef`)
now asks whether to regenerate, like **Smart Strings** and **Smart Parameter Types** already did.
- **Key Separators** applies when you press Enter or leave the field, so typing asks to regenerate once.

## [1.3.2] - 2026-10-28

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Severnbli.LocalizationCodegen.Installer
public static partial class Installer
{
public const string PackageId = "com.severnbli.localization-codegen";
public const string Version = "1.3.2";
public const string Version = "1.3.3";

static Installer()
{
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Add the scoped registry and the dependency to `Packages/manifest.json`:
}
],
"dependencies": {
"com.severnbli.localization-codegen": "1.3.2"
"com.severnbli.localization-codegen": "1.3.3"
}
}
```
Expand Down Expand Up @@ -255,7 +255,7 @@ public static string Greeting(object arg0, int count)
- Variables provided by a **Global Variables Group** are not parameters; Unity resolves them.
- **Smart Parameter Types = Inferred** uses `int` for `plural`, `IEnumerable` for `list`, otherwise `object`.
- **Smart Parameter Types = Mapping** uses the types you set in the entry's [Smart Parameter Types metadata](#parameter-types) and infers the rest like `Inferred`.
- Changing **Smart Strings** or **Smart Parameter Types** asks whether to regenerate, since method signatures change.
- Changing **Smart Strings** or **Smart Parameter Types** asks whether to regenerate, since method signatures change. So does every other setting that changes the generated code, unless **Silently On Settings Change** is on.
- Placeholder differences between locales are reported as warnings. Enable **Fail CI On Smart String Mismatch** to make `CheckBatch` fail on them.
- **MethodsAndRefs** additionally emits `Ref.Greeting(...)` returning a `LocalizedString` whose arguments and local variables are set.

Expand All @@ -271,6 +271,8 @@ With **Smart Parameter Types = Mapping**, you choose parameter types per entry.
3. Click **Add All Parameters** to add a row for every variable the entry uses in any locale, pre-filled with the inferred type, then change the types you care about. **Add Parameter** adds a single variable.
4. Each row's name is a dropdown of the entry's variables, labelled with their formatters and locales (`count (plural; en, ru)`). A warning icon marks a row that generation would warn about; hover it for the reason.

Metadata edits regenerate when you save the table (**File > Save Project** or Ctrl+S), not on every click. Turn on **On Metadata Edit** to regenerate after each edit instead.

Rows you delete simply fall back to the inferred type. Outside the Table Editor, names can be typed by hand: the variable name as written in the string (`count`, or `0` for `{0}`).

```csharp
Expand Down Expand Up @@ -377,6 +379,8 @@ Open **Project Settings > Localization Codegen**, or **Window > Localization Cod
| String Tables | on | Generate classes for string table collections. Disabling deletes the matching files on the next run. |
| Asset Tables | on | Generate classes for asset table collections. Disabling deletes the matching files on the next run. |
| Regenerate On Changes | on | Debounced automatic regeneration after table edits and external (VCS) changes. |
| Silently On Settings Change | off | Regenerate without asking when a setting that changes the generated code is edited. Off asks first. Needs **Regenerate On Changes**. |
| On Metadata Edit | off | Regenerate after every edit of the Smart Parameter Types metadata. Off regenerates when the table is saved. Needs **Regenerate On Changes**. |
| Generate Reference Members | off | Emit the nested [`Ref` class](#reference-members). |
| XML Documentation | off | Add XML docs with the default locale text and smart string parameters. |
| Smart Strings | off (upgraded) / `Methods` (new) | `Off`, `Methods` or `MethodsAndRefs`. |
Expand Down
14 changes: 14 additions & 0 deletions Unity-Package/Assets/root/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [1.3.3] - 2026-10-28

### Added
- **Silently On Settings Change**: regenerate without asking when a setting that changes the generated code is
edited. Off by default.
- **On Metadata Edit**: regenerate on every edit of the **Smart Parameter Types** metadata. Off by default.

### Changed
- Editing **Smart Parameter Types** metadata no longer regenerates on every click; the code regenerates when the
table is saved.
- Every setting that changes the generated code (namespace, output folder, table kinds, members, naming, `.asmdef`)
now asks whether to regenerate, like **Smart Strings** and **Smart Parameter Types** already did.
- **Key Separators** applies when you press Enter or leave the field, so typing asks to regenerate once.

## [1.3.2] - 2026-10-28

### Added
Expand Down
6 changes: 6 additions & 0 deletions Unity-Package/Assets/root/Editor/CodegenSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public sealed class CodegenSettings : ScriptableSingleton<CodegenSettings>
// Options introduced in 1.3.1. Off by default, so no migration is needed.
[SerializeField] private bool generateLoadTable;

// Options introduced in 1.3.3. Off by default, so no migration is needed.
[SerializeField] private bool regenerateSilently;
[SerializeField] private bool regenerateOnMetadataEdit;

public bool SetupCompleted { get => setupCompleted; set => setupCompleted = value; }
public string OutputFolder { get => outputFolder; set => outputFolder = value; }
public string Namespace { get => generatedNamespace; set => generatedNamespace = value; }
Expand All @@ -62,6 +66,8 @@ public sealed class CodegenSettings : ScriptableSingleton<CodegenSettings>
public bool FailOnSmartStringMismatch { get => failOnSmartStringMismatch; set => failOnSmartStringMismatch = value; }
public bool GenerateUniTask { get => generateUniTask; set => generateUniTask = value; }
public bool GenerateLoadTable { get => generateLoadTable; set => generateLoadTable = value; }
public bool RegenerateSilently { get => regenerateSilently; set => regenerateSilently = value; }
public bool RegenerateOnMetadataEdit { get => regenerateOnMetadataEdit; set => regenerateOnMetadataEdit = value; }

public SmartStringMode SmartStrings
{
Expand Down
73 changes: 58 additions & 15 deletions Unity-Package/Assets/root/Editor/SettingsGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ internal static class Content
"Generate classes for asset table collections. Disabling this deletes the matching generated files on the next run.");
public static readonly GUIContent AutoRegenerate = new GUIContent("Regenerate On Changes",
"Automatically regenerate when table collections or entries change.");
public static readonly GUIContent RegenerateSilently = new GUIContent("Silently On Settings Change",
"Regenerate without asking when a setting that changes the generated code is edited. " +
"Off asks first.");
public static readonly GUIContent RegenerateOnMetadataEdit = new GUIContent("On Metadata Edit",
"Regenerate on every edit of the Smart Parameter Types metadata. Off regenerates when the table is saved.");

public static readonly GUIContent SmartStrings = new GUIContent("Smart Strings",
"Generate methods with parameters for smart string entries. Off keeps the 1.0 behaviour.");
Expand Down Expand Up @@ -89,6 +94,7 @@ public static bool Draw()

var oldSmartStrings = s.SmartStrings;
var oldSmartParamTypes = s.SmartParamTypes;
var oldOutput = OutputSettingsKey(s);
var oldLabelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = LabelWidth;
EditorGUI.BeginChangeCheck();
Expand All @@ -108,8 +114,8 @@ public static bool Draw()

var smartChanged = s.SmartStrings != oldSmartStrings || s.SmartParamTypes != oldSmartParamTypes;
// The setup wizard generates when it finishes, so it is not asked about.
if (smartChanged && s.SetupCompleted)
PromptRegenerate();
if (OutputSettingsKey(s) != oldOutput && s.SetupCompleted)
OnOutputSettingsChanged(s, smartChanged);
else
CodegenHooks.MarkDirtyExternal();

Expand All @@ -120,29 +126,54 @@ public static bool Draw()
return changed;
}

/// <summary>Every setting that changes the generated code. Settings outside it never ask to regenerate.</summary>
static string OutputSettingsKey(CodegenSettings s)
{
return string.Join("|", new[]
{
s.Namespace, s.OutputFolder, s.GenerateStringTables.ToString(), s.GenerateAssetTables.ToString(),
s.SmartStrings.ToString(), s.SmartParamTypes.ToString(), s.GenerateReferences.ToString(),
s.GenerateLoadTable.ToString(), s.GenerateUniTask.ToString(), s.GenerateXmlDocs.ToString(),
s.Naming.ToString(), s.KeySeparators, s.GenerateAsmdef.ToString()
});
}

/// <summary>
/// Regenerates after a setting that changes the generated code, asking first unless
/// <see cref="CodegenSettings.RegenerateSilently"/> is on. Without automatic regeneration only changes to the
/// method signatures ask, as nothing else would regenerate either.
/// </summary>
static void OnOutputSettingsChanged(CodegenSettings s, bool signaturesChanged)
{
if (s.AutoRegenerate && s.RegenerateSilently)
CodegenHooks.MarkDirtyExternal();
else if (s.AutoRegenerate || signaturesChanged)
PromptRegenerate(signaturesChanged);
}

static bool s_RegeneratePromptPending;
static bool s_RegeneratePromptSignatures;

/// <summary>
/// Asks whether to regenerate after the smart string settings change, since they change method signatures.
/// The dialog opens after the current GUI pass, and only once for several changes in a row.
/// Asks whether to regenerate after the settings change. The dialog opens after the current GUI pass, and only
/// once for several changes in a row.
/// </summary>
static void PromptRegenerate()
static void PromptRegenerate(bool signaturesChanged)
{
s_RegeneratePromptSignatures |= signaturesChanged;
if (s_RegeneratePromptPending)
return;

s_RegeneratePromptPending = true;
EditorApplication.delayCall += () =>
{
var message = s_RegeneratePromptSignatures
? "The smart string settings changed the generated method signatures. Regenerate the code now?"
: "The settings changed the generated code. Regenerate the code now?";
s_RegeneratePromptPending = false;
if (EditorUtility.DisplayDialog(
"Localization Codegen",
"The smart string settings changed the generated method signatures. Regenerate the code now?",
"Regenerate",
"Later"))
{
s_RegeneratePromptSignatures = false;
if (EditorUtility.DisplayDialog("Localization Codegen", message, "Regenerate", "Later"))
CodeGenerator.Run(new GenerateOptions { IsAutomatic = false, PromptOnMassDeletion = true });
}
};
}

Expand Down Expand Up @@ -328,7 +359,8 @@ static void ApplyOwnerChoice(CodegenSettings s, OwningAssembly owner, bool addRe
{
s.GenerateAsmdef = true;
s.SaveSettings();
CodegenHooks.MarkDirtyExternal();
if (s.SetupCompleted)
OnOutputSettingsChanged(s, signaturesChanged: false);
}

s_OwnerCacheKey = null;
Expand All @@ -339,6 +371,13 @@ static void DrawTables(CodegenSettings s)
s.GenerateStringTables = EditorGUILayout.Toggle(Content.StringTables, s.GenerateStringTables);
s.GenerateAssetTables = EditorGUILayout.Toggle(Content.AssetTables, s.GenerateAssetTables);
s.AutoRegenerate = EditorGUILayout.Toggle(Content.AutoRegenerate, s.AutoRegenerate);
using (new EditorGUI.DisabledScope(!s.AutoRegenerate))
using (new EditorGUI.IndentLevelScope())
{
s.RegenerateSilently = EditorGUILayout.Toggle(Content.RegenerateSilently, s.RegenerateSilently);
s.RegenerateOnMetadataEdit =
EditorGUILayout.Toggle(Content.RegenerateOnMetadataEdit, s.RegenerateOnMetadataEdit);
}

if (!s.GenerateStringTables && !s.GenerateAssetTables)
EditorGUILayout.HelpBox("Both table kinds are off, so nothing will be generated.", MessageType.Warning);
Expand Down Expand Up @@ -373,7 +412,8 @@ static void DrawMembers(CodegenSettings s)
static void DrawNaming(CodegenSettings s)
{
s.Naming = (NamingConvention)EditorGUILayout.EnumPopup(Content.Naming, s.Naming);
s.KeySeparators = EditorGUILayout.TextField(Content.KeySeparators, s.KeySeparators);
// Delayed, so typing several characters asks to regenerate once.
s.KeySeparators = EditorGUILayout.DelayedTextField(Content.KeySeparators, s.KeySeparators);
}

static void DrawAdvanced(CodegenSettings s)
Expand Down Expand Up @@ -414,8 +454,11 @@ static void PickOutputFolder(CodegenSettings s)
if (s.OutputFolder != previous)
{
s.SaveSettings();
CodegenHooks.MarkDirtyExternal();
OnOutputFolderChanged();
if (s.SetupCompleted)
OnOutputSettingsChanged(s, signaturesChanged: false);
else
CodegenHooks.MarkDirtyExternal();
}

GUI.FocusControl(null);
Expand Down
16 changes: 12 additions & 4 deletions Unity-Package/Assets/root/Editor/SmartParameterTypesDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Severnbli.LocalizationCodegen.Editor
/// <summary>
/// Editor for <see cref="SmartParameterTypes"/>: picks names from the variables the entry uses in any locale,
/// adds every variable at once, and shows the warnings generation would report.
/// Edits regenerate only with <see cref="CodegenSettings.RegenerateOnMetadataEdit"/>; otherwise the asset
/// postprocessor does once the table is saved.
/// </summary>
[CustomPropertyDrawer(typeof(SmartParameterTypes))]
sealed class SmartParameterTypesDrawer : PropertyDrawer
Expand Down Expand Up @@ -115,7 +117,7 @@ static void DrawBody(Rect rect, SerializedProperty property, SerializedProperty
if (remove >= 0)
{
parameters.DeleteArrayElementAtIndex(remove);
CodegenHooks.MarkDirtyExternal();
OnEdited();
}
}

Expand Down Expand Up @@ -195,7 +197,7 @@ static bool DrawRow(
if (EditorGUI.EndChangeCheck())
{
nameProperty.stringValue = typed;
CodegenHooks.MarkDirtyExternal();
OnEdited();
}
}
else
Expand All @@ -210,7 +212,7 @@ static bool DrawRow(
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(typeRect, typeProperty, GUIContent.none);
if (EditorGUI.EndChangeCheck())
CodegenHooks.MarkDirtyExternal();
OnEdited();

var normalized = SmartParameterMapping.NormalizeName(name);
var duplicate = normalized.Length > 0 && !seen.Add(normalized);
Expand Down Expand Up @@ -294,7 +296,13 @@ static void Modify(Target target, Action<SerializedProperty> change)

change(parameters);
serializedObject.ApplyModifiedProperties();
CodegenHooks.MarkDirtyExternal();
OnEdited();
}

static void OnEdited()
{
if (CodegenSettings.instance.RegenerateOnMetadataEdit)
CodegenHooks.MarkDirtyExternal();
}
}
}
8 changes: 6 additions & 2 deletions Unity-Package/Assets/root/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Add the scoped registry and the dependency to `Packages/manifest.json`:
}
],
"dependencies": {
"com.severnbli.localization-codegen": "1.3.2"
"com.severnbli.localization-codegen": "1.3.3"
}
}
```
Expand Down Expand Up @@ -255,7 +255,7 @@ public static string Greeting(object arg0, int count)
- Variables provided by a **Global Variables Group** are not parameters; Unity resolves them.
- **Smart Parameter Types = Inferred** uses `int` for `plural`, `IEnumerable` for `list`, otherwise `object`.
- **Smart Parameter Types = Mapping** uses the types you set in the entry's [Smart Parameter Types metadata](#parameter-types) and infers the rest like `Inferred`.
- Changing **Smart Strings** or **Smart Parameter Types** asks whether to regenerate, since method signatures change.
- Changing **Smart Strings** or **Smart Parameter Types** asks whether to regenerate, since method signatures change. So does every other setting that changes the generated code, unless **Silently On Settings Change** is on.
- Placeholder differences between locales are reported as warnings. Enable **Fail CI On Smart String Mismatch** to make `CheckBatch` fail on them.
- **MethodsAndRefs** additionally emits `Ref.Greeting(...)` returning a `LocalizedString` whose arguments and local variables are set.

Expand All @@ -271,6 +271,8 @@ With **Smart Parameter Types = Mapping**, you choose parameter types per entry.
3. Click **Add All Parameters** to add a row for every variable the entry uses in any locale, pre-filled with the inferred type, then change the types you care about. **Add Parameter** adds a single variable.
4. Each row's name is a dropdown of the entry's variables, labelled with their formatters and locales (`count (plural; en, ru)`). A warning icon marks a row that generation would warn about; hover it for the reason.

Metadata edits regenerate when you save the table (**File > Save Project** or Ctrl+S), not on every click. Turn on **On Metadata Edit** to regenerate after each edit instead.

Rows you delete simply fall back to the inferred type. Outside the Table Editor, names can be typed by hand: the variable name as written in the string (`count`, or `0` for `{0}`).

```csharp
Expand Down Expand Up @@ -377,6 +379,8 @@ Open **Project Settings > Localization Codegen**, or **Window > Localization Cod
| String Tables | on | Generate classes for string table collections. Disabling deletes the matching files on the next run. |
| Asset Tables | on | Generate classes for asset table collections. Disabling deletes the matching files on the next run. |
| Regenerate On Changes | on | Debounced automatic regeneration after table edits and external (VCS) changes. |
| Silently On Settings Change | off | Regenerate without asking when a setting that changes the generated code is edited. Off asks first. Needs **Regenerate On Changes**. |
| On Metadata Edit | off | Regenerate after every edit of the Smart Parameter Types metadata. Off regenerates when the table is saved. Needs **Regenerate On Changes**. |
| Generate Reference Members | off | Emit the nested [`Ref` class](#reference-members). |
| XML Documentation | off | Add XML docs with the default locale text and smart string parameters. |
| Smart Strings | off (upgraded) / `Methods` (new) | `Off`, `Methods` or `MethodsAndRefs`. |
Expand Down
2 changes: 1 addition & 1 deletion Unity-Package/Assets/root/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Generation",
"Code Generation"
],
"version": "1.3.2",
"version": "1.3.3",
"unity": "2021.3",
"description": "C# classes and properties generator from Unity Localization tables",
"documentationUrl": "https://github.com/Severnbli/localization-codegen/blob/main/README.md",
Expand Down
Loading