# AddStringVariant(string, string, string)

> Adds or updates a variant value for a string key in this table.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Localization](/engine/6000.7/script-reference/unity/localization.md)
* **Assembly:** UnityEngine.LocalizationRuntimeModule

```csharp
public StringEntry AddStringVariant(string key, string variantKey, string value)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The key text; added to the shared data when new.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The selector key this value applies to, for example `"Steam"`.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The localized value to store for this locale and variant.

### Returns

| Type                                                                             | Description                                                    |
| -------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| [StringEntry](/engine/6000.7/script-reference/unity/localization/stringentry.md) | The added or updated entry, or `null` when it cannot be added. |

### 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](/engine/6000.7/script-reference/unity/localization/variantselectormetadata.md), 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](/engine/6000.7/script-reference/unity/localization/ivariantselector/currentkey.md) 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](/engine/6000.7/script-reference/unity/localization/resourcetable/addstringentry.md), [ResourceTable.RemoveVariant](/engine/6000.7/script-reference/unity/localization/resourcetable/removevariant.md), [IVariantSelector](/engine/6000.7/script-reference/unity/localization/ivariantselector.md)

Make a key vary by storefront from script.

### Examples

```csharp
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");
        }
    }
}
```
