| Parameter | Description |
|---|---|
| key | The key text; added to the shared data when new. |
| variantKey | The selector key this value applies to, for example "Steam". |
| value | The localized value to store for this locale and variant. |
stringEntry
The added or updated entry, or null when it cannot be added.
Adds or updates a variant value for a string key in this table.
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 variantKey; otherwise resolution falls
back to the entry's default value. Returns null when no shared data is assigned, either
name is empty, or the key holds a non-string entry.
Additional resources: ResourceTable.AddStringEntry, ResourceTable.RemoveVariant, IVariantSelector
Make a key vary by storefront from script.
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");
}
}
}