Method GetLocalizedStringAsync
GetLocalizedStringAsync()
Provides a translated string from a String
Declaration
public AsyncOperationHandle<string> GetLocalizedStringAsync()
Returns
Type | Description |
---|---|
Async |
Returns the loading operation for the request. |
Remarks
The Unity
Examples
This example shows how Get
public class LocalizedStringGetExample : MonoBehaviour
{
public Text myText;
public LocalizedString myString = new LocalizedString
{
TableReference = "My String Table",
TableEntryReference = "My Game Text"
};
void OnEnable()
{
LocalizationSettings.SelectedLocaleChanged += LocaleChanged;
LoadString();
}
void OnDisable()
{
LocalizationSettings.SelectedLocaleChanged -= LocaleChanged;
}
void LocaleChanged(Locale locale)
{
LoadString();
}
void LoadString()
{
var operation = myString.GetLocalizedStringAsync();
UpdateString(operation);
}
void UpdateString(AsyncOperationHandle<string> value)
{
if (!value.IsDone)
{
// Defer the callback until the operation is finished
value.Completed += UpdateString;
return;
}
myText.text = value.Result;
}
}
This example shows how Get
public class LocalizedStringSynchronousGetExample : MonoBehaviour
{
public Text myText;
public LocalizedString myString = new LocalizedString
{
TableReference = "My String Table",
TableEntryReference = "My Game Text"
};
void OnEnable()
{
LocalizationSettings.SelectedLocaleChanged += LocaleChanged;
LoadString();
}
void OnDisable()
{
LocalizationSettings.SelectedLocaleChanged -= LocaleChanged;
}
void LocaleChanged(Locale locale)
{
LoadString();
}
void LoadString()
{
var operation = myString.GetLocalizedStringAsync();
operation.WaitForCompletion(); // Force synchronous loading
myText.text = operation.Result;
}
}
GetLocalizedStringAsync(params object[])
Provides a translated string from a String
Declaration
public AsyncOperationHandle<string> GetLocalizedStringAsync(params object[] arguments)
Parameters
Type | Name | Description |
---|---|---|
object[] | arguments | The arguments to pass into the Smart String formatter or String.Format. |
Returns
Type | Description |
---|---|
Async |
Returns the loading operation for the request. |
GetLocalizedStringAsync(IList<object>)
Provides a translated string from a String
Declaration
public AsyncOperationHandle<string> GetLocalizedStringAsync(IList<object> arguments)
Parameters
Type | Name | Description |
---|---|---|
IList<object> | arguments | The arguments to pass into the Smart String formatter or String.Format. |
Returns
Type | Description |
---|---|
Async |
Returns the loading operation for the request. |