Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


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

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.

Returns

Type

Description

StringEntryThe 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, 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.
Make 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"); } }}