Hello i wanna change the text from a key in a localized string table, i want to change this “” to another thing i want, i already did it in the console but i cant get to change it in the actual table, sorry still new to the localization package in unity
Is this in Editor or player?
In editor you can use this to get the collection, then get the string table and finally get the entry. Class LocalizationEditorSettings | Localization | 1.4.5
Yes is in editor, i kinda got the key selected but i got the key name not what´s inside that key

Remove the ‘.Key’ part and you will have the entry. You can then set the Localized field.
Make sure to also mark the table as dirty using
EditorUtility.SetDirty.
Now i have another doubt, can i check if a key has the “” thing and then change the text ui instead of the string key? Cause right know i access the key checks that it has the “” then change it in the console but i dont know if it’s better to change it in the text or in the key itself
public class LocalizationIconData : ScriptableObject
{
public IconFlow[] Icons;
int _index = 1;
public string spriteSheetName;
public string actionName;
private void OnValidate()
{
GetTableKey();
LocalizeText();
}
public string LocalizeText()
{
string text = Icons[0].StringReference.GetLocalizedString();
//string actionName = "EmojiOne";
//string spriteSheet = "Smiling face with smiling eyes";
Debug.Log(text);
if (text.Contains("<icono>"))
{
Debug.Log("it has it");
text = text.Replace("icono", $"sprite=\"{spriteSheetName}\" name=\"{actionName}\"");
Debug.Log(text);
}
else
{
Debug.Log("no lo tiene");
}
return text;
}
private void GetTableKey()
{
var collection = UnityEditor.Localization.LocalizationEditorSettings.GetStringTableCollection(Icons[_index].StringReference.TableReference);
if (collection != null)
{
var keyName = collection.SharedData.GetEntryFromReference(Icons[_index].StringReference.TableEntryReference);
actionName = keyName.ToString();
}
}
I would use a smart string.
instead of
“New Game ”
do
“New Game <sprite=”{spriteSheetName}" name=“{actionName}”>";
Now pass a reference to your instance as an argument to GetLocalizedString.
public class LocalizationIconData : ScriptableObject
{
public IconFlow[] Icons;
int _index = 1;
public string spriteSheetName;
public string actionName;
Dictionary<string, string> m_SpriteArguments = new Dictionary<string, string>();
private void OnValidate()
{
LocalizeText();
}
public string LocalizeText()
{
string text = Icons[0].StringReference.GetLocalizedString(this);
return text;
}
}
It will now extract the fields spriteSheetName and actionName from the argument using the Reflection Source, if the smart string is not using those arguments then it will just do nothing. This way you keep the same code for strings with and without a sprite.
Okay, i’ll try using the smart string and let you know if i find the way to make it work for me
Is there a way that i change the action name via script or when i choose the enum i want it changes the action name and then changes the locale variable?

like right now my local variables are set at spriteSheetName = SpritesPS and actionName = north but i want it to be south because that’s what i chose in the inspector but it’s still north
Are you using a custom inspector? What does your code look like? Its not saving the changes via the inspector?
Yeah its not, let me show you this is my inspector

And this is the two scripts im using, one for the icons items and the other for whatever it’s going on outside. My plan is using the enum of icons to change the action name in the smart string, cause the sprite sheet name is actually gonna be the same all the time. I don’t know if maybe im not doing in it in the right script and maybe that’s why im not getting what i want
Script #1
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.Localization;
using UnityEngine.Localization.SmartFormat.PersistentVariables;
[CreateAssetMenu(menuName = "LocalizedIconData", fileName = "LocalizedIconData")]
public class LocalizationIconData : ScriptableObject
{
public IconFlow[] Icons;
int _index = 1;
Dictionary<string, string> m_SpriteArguments = new Dictionary<string, string>();
public string spriteSheetName;
// public string actionName;
private void OnValidate()
{
//GetTableKey();
LocalizeText();
}
public string LocalizeText()
{
string text = Icons[0].StringReference.GetLocalizedString(this);
(Icons[0].StringReference["actionName"] as StringVariable).Value = "south";
return text;
/* string text = Icons[0].StringReference.GetLocalizedString();
//string actionName = "EmojiOne";
//string spriteSheet = "Smiling face with smiling eyes";
Debug.Log(text);
if (text.Contains("<icono>"))
{
Debug.Log("it has it");
text = text.Replace("icono", $"sprite=\"{spriteSheetName}\" name=\"{actionName}\"");
Debug.Log(text);
}
else
{
Debug.Log("no lo tiene");
}
return text;*/
}
private void GetTableKey()
{
var collection = UnityEditor.Localization.LocalizationEditorSettings.GetStringTableCollection(Icons[_index].StringReference.TableReference);
if (collection != null)
{
var keyName = collection.SharedData.GetEntryFromReference(Icons[_index].StringReference.TableEntryReference);
actionName = keyName.ToString();
}
}
}
and this is script #2
using System;
using UnityEngine;
using TMPro;
using System.Collections.Generic;
using UnityEngine.Localization;
public enum IconType
{
north = 0,
south = 1,
}
[Serializable]
public class IconFlow
{
public LocalizedString StringReference;
public IconType icons;
public string actionName;
public void GetActionName(IconType icon)
{
if(icon == IconType.north)
{
string enumAsString = nameof(IconType.north);
actionName = enumAsString;
}
else if(icon == IconType.south)
{
string enumAsString = nameof(IconType.south);
actionName = enumAsString;
}
}
}
public class LocalizedIcons : MonoBehaviour
{
}
Okay i made it work but now i realized im not using smart strings, so im back at the beginning with trying to change the content of a key, i have the selected string reference and what i want to have, i just need to change it in the string table entry with whatever i have in my custom inspector, that is a string that i choose
Are you using the Editor settings class. That will let you change the values
Im sorry to ask but how do you use the editor settings class?



