Localization in scripts

More
4 years 3 weeks ago #4063 by bob
Localization in scripts was created by bob
Hello
I'm new to this tool and I'm trying to figure out how use it best with the scripts I already have.

I have this Dialog script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class Dialogue
{

    public string name;

    [TextArea(3, 10)]
    public string[] sentences;


}

I access it from this and send it to my dialog manager.
using System.Collections;
using UnityEngine.Events;
using System.Collections.Generic;
using UnityEngine;

public class DialogueTrigger : MonoBehaviour
{

    public Dialogue dialogue;
    public DialogueManager DM;
    public bool Ended = false;
    public UnityEvent m_MyEventStart;
    public  UnityEvent m_MyEvent;

    public bool Use2ndBox = false;

    private void Start()
    {
        DM = FindObjectOfType<DialogueManager>();
    }

    public void TriggerDialogue()
    {
        m_MyEventStart.Invoke();
        DM.StartDialogue(dialogue, this, Use2ndBox);
    }
    public void TriggerEvents()
    {
        m_MyEvent.Invoke();
    }
}

Each Prefab in scenes that have the DialogTrigger has different text.

Hope you can help or point me in the right direction.

Thanks
Bob

Please Log in or Create an account to join the conversation.

More
4 years 3 weeks ago #4064 by Frank
Replied by Frank on topic Localization in scripts
The easiest way is to replace string by LocalizedString.

LocalizedString works like a string, but when you assign it, you assign the Term Name, and when you read its value it returns the translation to the current language.

inter-illusion.com/assets/I2Localization...ocalizedStrings.html

LocalizedString locString = "Term2"; LocalizationManager.CurrentLanguage = "English"; string translation = locString; // returns the translation of Term2 to English (e.g. 'This is an example') LocalizationManager.CurrentLanguage = "Spanish"; string translation = locString; // returns the translation of Term2 to Spanish (e.g. 'Este es un ejemplo') [/code Their inspector is also shown as a popup to select the term. Hope that helps, Frank[code]
LocalizedString locString = "Term2";

LocalizationManager.CurrentLanguage = "English";
string translation = locString; // returns the translation of Term2 to English (e.g. 'This is an example')

LocalizationManager.CurrentLanguage = "Spanish";
string translation = locString; // returns the translation of Term2 to Spanish (e.g. 'Este es un ejemplo')
[/code

Their inspector is also shown as a popup to select the term.

Hope that helps,
Frank

Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out
The following user(s) said Thank You: bob

Please Log in or Create an account to join the conversation.

More
4 years 3 weeks ago - 4 years 3 weeks ago #4065 by bob
Replied by bob on topic Localization in scripts
Works like a charm! thank you for the quick reply
Last edit: 4 years 3 weeks ago by bob.

Please Log in or Create an account to join the conversation.

Time to create page: 0.402 seconds
Template by JoomlaShine