Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

ResourceTable.AddStringVariant

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public stringEntry AddStringVariant(string key, string variantKey, string value);

Parameters

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.

Returns

stringEntry The added or updated entry, or null when it cannot be added.

Description

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