AddStringVariant(string, string, string)
Adds or updates a variant value for a string key in this table.
Read time 1 minuteLast updated 10 days ago
Definition
- Type: Method
- Namespace: Unity.Localization
- Assembly: UnityEngine.LocalizationRuntimeModule
public StringEntry AddStringVariant(string key, string variantKey, string value)
Parameters
Returns
Type | Description |
|---|---|
| StringEntry | The added or updated entry, or |
Remarks
Makes the key variant-driven when it is not already: the key is created when missing, a plain string entry is promoted to a variant entry keeping its value as the default, and the variant key is registered on the key's VariantSelectorMetadata, created without a selector when the key has none, so the key inherits the collection or global selector. The value applies when the selector's IVariantSelector.CurrentKey equals ; otherwise resolution falls back to the entry's default value. Returns when no shared data is assigned, either name is empty, or the key holds a non-string entry.
variantKeynullMake a key vary by storefront from script.
Examples
namespace Unity.Localization.Samples{ public static class AddVariantByScriptExample { public static void MakeWishlistVaryByStorefront(ResourceTable table) { // The default value, used wherever no variant matches. table.AddStringEntry("wishlist", "Add to wishlist"); // The selector lives on the shared key, so every locale resolves the same way. var key = table.SharedData.GetEntry("wishlist"); if (key.Metadata.GetMetadata<VariantSelectorMetadata>() == null) key.Metadata.AddMetadata(new VariantSelectorMetadata(new StorefrontVariantSelector())); // The value this locale shows when the selector reports "GOG". table.AddStringVariant("wishlist", "GOG", "Add to GOG wishlist"); } public static void RemoveTheVariant(ResourceTable table) { table.RemoveVariant("wishlist", "GOG"); } }}