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

ResourceTable.AddStringEntry(string,string,bool?)

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

Parameters

Parameter Description
key The key text; added to the shared data when new.
value The localized value to store for this locale.
isSmart Whether the value is a Smart String, formatted at resolve time; omit it to leave the key's flag unchanged.

Returns

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

Description

Adds or updates a plain string entry for a key.

Adds the key to ResourceTable.SharedData when it is new, then stores the value for this locale. When an entry already exists for the key, its value is overwritten. When isSmart is supplied it is stored on the shared key, so it applies to every locale and can turn an existing key back into a plain string; when it is omitted the key's existing flag is left unchanged. Returns null when no shared data is assigned or the key is empty.

Additional resources: ResourceTable.AddEntry, ResourceTable.GetEntry, IStringEntry

<para>Add plain and Smart String entries to a table.</para>

using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples { public class ResourceTableAddStringEntryExample { public void Run() { var shared = ScriptableObject.CreateInstance<SharedTableData>(); var table = ScriptableObject.CreateInstance<ResourceTable>(); table.SharedData = shared; table.LocaleIdentifier = "en";

StringEntry greeting = table.AddStringEntry("Greeting", "Hello"); Debug.Log(greeting.Value); // Hello

table.AddStringEntry("Score", "You scored {0}", isSmart: true); } } }