diff --git a/.gitignore b/.gitignore
index 92f6db9..299dcd5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,5 @@ obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
-build/
\ No newline at end of file
+build/
+.vs/
\ No newline at end of file
diff --git a/ConfigLocale.cs b/ConfigLocale.cs
index 52230f8..20ceef8 100644
--- a/ConfigLocale.cs
+++ b/ConfigLocale.cs
@@ -1,4 +1,5 @@
-using Elements.Core;
+using BepInEx.Configuration;
+using Elements.Core;
namespace BepisLocaleLoader;
@@ -19,4 +20,62 @@ public ConfigLocale(LocaleString name, LocaleString description)
public LocaleString Name;
public LocaleString Description;
+}
+
+public static class ConfigLocaleHelper
+{
+ ///
+ /// Create a new setting with localized name and description. The resulting locale keys will be: Name = Settings.{guid}.{section}.{key}, Description = Settings.{guid}.{section}.{key}.Description
+ ///
+ /// Type of the value contained in this setting.
+ /// The file that the setting will be bound to.
+ /// The GUID of your mod, this is used to make the locale key unique from other plugins.
+ /// Section/category/group of the setting. Settings are grouped by this.
+ /// Name of the setting.
+ /// Value of the setting if the setting was not created yet.
+ /// The english description of your config key. This will be visible when editing config files via mod managers or manually.
+ public static ConfigEntry BindLocalized(this ConfigFile config, string guid, string section, string key, T defaultValue, string englishDescription)
+ {
+ return config.BindLocalized(guid, new ConfigDefinition(section, key), defaultValue, new ConfigDescription(englishDescription));
+ }
+
+ ///
+ /// Create a new setting with localized name and description. The resulting locale keys will be: Name = Settings.{guid}.{section}.{key}, Description = Settings.{guid}.{section}.{key}.Description
+ ///
+ /// Type of the value contained in this setting.
+ /// The file that the setting will be bound to.
+ /// The GUID of your mod, this is used to make the locale key unique from other plugins.
+ /// Section/category/group of the setting. Settings are grouped by this.
+ /// Name of the setting.
+ /// Value of the setting if the setting was not created yet.
+ /// Description and other metadata of the setting. The text description will be visible when editing config files via mod managers or manually.
+ public static ConfigEntry BindLocalized(this ConfigFile config, string guid, string section, string key, T defaultValue, ConfigDescription configDescription = null)
+ {
+ return config.BindLocalized(guid, new ConfigDefinition(section, key), defaultValue, configDescription);
+ }
+
+ ///
+ /// Create a new setting with localized name and description. The resulting locale keys will be: Name = Settings.{guid}.{Section}.{Key}, Description = Settings.{guid}.{Section}.{Key}.Description
+ ///
+ /// Type of the value contained in this setting.
+ /// The file that the setting will be bound to.
+ /// The GUID of your mod, this is used to make the locale key unique from other plugins.
+ /// Section and Key of the setting.
+ /// Value of the setting if the setting was not created yet.
+ /// Description and other metadata of the setting. The text description will be visible when editing config files via mod managers or manually.
+ public static ConfigEntry BindLocalized(this ConfigFile config, string guid, ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
+ {
+ var localeName = $"Settings.{guid}.{configDefinition.Section}.{configDefinition.Key}";
+ var localeDescription = localeName + ".Description";
+ var locale = new ConfigLocale(localeName, localeDescription);
+ if(configDescription == null)
+ {
+ configDescription = new ConfigDescription(string.Empty, null, locale);
+ }
+ else
+ {
+ configDescription = new ConfigDescription(configDescription.Description, configDescription.AcceptableValues, [..configDescription.Tags, locale]);
+ }
+ return config.Bind(configDefinition, defaultValue, configDescription);
+ }
}
\ No newline at end of file
diff --git a/README.md b/README.md
index 1023da3..3b04ac0 100644
--- a/README.md
+++ b/README.md
@@ -10,14 +10,33 @@ A [Resonite](https://resonite.com/) mod that Loads locale files for Plugins.
# Example config using ConfigDescription
+You can add locale to a config entry by adding a `ConfigLocale` in your `ConfigDescription` like this:
+
```cs
private static ConfigEntry exampleConfigItem;
public override void Load()
{
- exampleConfigItem = Config.Bind("General", "exampleConfigItem", false, new ConfigDescription("exampleConfigItem Description", null, new ConfigLocale("Settings.dev.author.myPlugin.config.Key", "Settings.dev.author.myPlugin.config.Description")));
+ exampleConfigItem = Config.Bind("General", "exampleConfigItem", false, new ConfigDescription("exampleConfigItem Description", null, new ConfigLocale("Settings.dev.author.myPlugin.General.exampleConfigItem", "Settings.dev.author.myPlugin.General.exampleConfigItem.Description")));
}
```
+Or you can use the `ConfigLocaleHelper` class which provides the `BindLocalized` extension method like this:
+
+```cs
+private static ConfigEntry exampleConfigItem;
+public override void Load()
+{
+ // Generates the following locale keys:
+ // Name: "Settings.dev.author.myPlugin.General.exampleConfigItem"
+ // Description: "Settings.dev.author.myPlugin.General.exampleConfigItem.Description"
+ exampleConfigItem = Config.BindLocalized("dev.author.myPlugin", "General", "exampleConfigItem", false, "exampleConfigItem Description");
+ // NOTE: If you are using the ResoniteModding plugin template you can use `PluginMetadata.GUID` instead of `"dev.author.myPlugin"`
+}
+```
+
+When defining config entries with locale, it's still recommended to provide the entry's english description ("exampleConfigItem Description" in this case), as this will be visible when editing the config file manually or via mod managers.
+
+
## Adding Locale Strings Manually
You can register a single localized string in code with: