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

SharedTableData.RenameKey

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 bool RenameKey(long id, string newKey);

Parameters

Parameter Description
id The stable id of the key to rename.
newKey The new key text.

Returns

bool true when the key was renamed or already had the requested name; otherwise, false.

Description

Renames a key while keeping its id.

The key's stable id does not change, so existing translations keyed by id continue to resolve. Returns false when the new name is empty, no key uses the id, or another key already uses the new name. Renaming a key to its current name succeeds and makes no change.

Additional resources: SharedTableData.AddKey, SharedTableData.GetId

<para>Fix a typo in a key without changing its id.</para>

using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples { public class SharedTableDataRenameKeyExample { public void Run() { var sharedData = ScriptableObject.CreateInstance<SharedTableData>(); long id = sharedData.AddKey("GREETNIG").Id; // typo

bool renamed = sharedData.RenameKey(id, "GREETING");

Debug.Log(renamed); // True Debug.Log(sharedData.GetKey(id)); // GREETING, same id } } }