Method ForceRefresh
ForceRefresh()
Raises the SelectedLocaleChanged event to notify listeners that the selected locale has changed, triggering a refresh of localized strings and assets.
Declaration
public void ForceRefresh()
Remarks
This method triggers the SelectedLocaleChanged event, which typically forces all subscribing systems to update their displayed content based on the current locale. Use this after modifying localization assets, such as string tables, to immediately reflect the latest translations throughout the application. If no locale is currently selected, the event will be raised with a null value.
Examples
The following example uses ForceRefresh to force an update after updating a string table entry.
public class ForceUpdateExample : MonoBehaviour
{
public LocalizedString myString = new LocalizedString("MyTable", "MyEntry");
void OnEnable()
{
myString.StringChanged += UpdateText;
}
void OnDisable()
{
myString.StringChanged -= UpdateText;
}
void UpdateText(string text)
{
Debug.Log("The value is " + text);
}
// This method is called to change the value in the string table.
[ContextMenu("Change Source Value")]
public void ChangeSourceValue()
{
// Get the table and entry, and update the value.
var tableEntry = LocalizationSettings.StringDatabase.GetTableEntry(myString.TableReference, myString.TableEntryReference);
tableEntry.Entry.Value = "New Value";
// Force a refresh to update everything, including any uses of the changed entry.
LocalizationSettings.Instance.ForceRefresh();
}
}