Topic: Language Select from Main Menu or Options?

I'm nearly finished with my UFE game after several years of development.

I want to make buttons on the Options Screen or Main Menu screen to select a language, but am having trouble figuring out the code.

I have already added the languages in the UFE editor, but I need help adding the several lines of code to the game to make it work.

Can someone please help me out with this? Just let me know what I need to copy/paste into where.

Looking forward to chatting.


REPOSTING in the right section this time smile

Share

Thumbs up Thumbs down

Re: Language Select from Main Menu or Options?

BUMP! need help with this ASAP. willing to send some cash via Paypal to the first person that can help.

Share

Thumbs up Thumbs down

Re: Language Select from Main Menu or Options?

Are you using any other Language add-on? Such as Smart Localization? Or are you purely using the Language option from the global config.

Btw, as far as I have ever been able to tell, the global config language values aren't actually hooked up into the game once Canvas UI was added to the system.

Share

Thumbs up Thumbs down

Re: Language Select from Main Menu or Options?

i am not using any other plugins currently but I am open to ideas. I know that the UFE option doesn't change the button text, but getting it working would certainly be a start.

Share

Thumbs up Thumbs down

5 (edited by MrPonton 2016-09-03 13:29:13)

Re: Language Select from Main Menu or Options?

anthonie121 wrote:

i am not using any other plugins currently but I am open to ideas. I know that the UFE option doesn't change the button text, but getting it working would certainly be a start.

I'll see if I can whip up what I did as a tutorial. Could take a week though as I am pressed with my own deadlines. Though I haven't hooked it up in a button to language select, but mainly because I haven't designed my UI for that area yet.

Share

Thumbs up Thumbs down

6 (edited by MrPonton 2016-09-06 21:26:06)

Re: Language Select from Main Menu or Options?

Here's the code I did for integrating SmartLocalization into my UFE game.

First, install SmartLocalization and set up the primary and at least a secondary language. For my case, I used Japanese as my secondary. Then add a new language to the Global UFE Config asset with the same name of the language.

Second, open up UFE.cs and at the top, add the following using statement:

using SmartLocalization;

Third, inside the Public Instance Properties region, add a static call to a new LanguageManager object, I called mine 'Localization':

#region public instance properties
public GlobalInfo UFE_Config;
public static LanguageManager Localization;
public string[] Languages;
public int UsingLanguage;

#endregion

Fourth, scroll down the class sheet to find the moment the Awake() calls 'SetLanguage()'. Then add the code to instantiate the Localization object and update the current language to whatever is the language option in the Global UFE Config asset file.

SetLanguage();

UFE.Localization = LanguageManager.Instance;

switch(UFE.config.selectedLanguage.languageName) {
      case "Japanese":
            Localization.ChangeLanguage(new SmartCultureInfo("ja-JP", "Japanese", "Japanese", false));
            break;
      default:
            Localization.ChangeLanguage(new SmartCultureInfo("en-US", "English", "English", false));
            break;
}

Fifth, create a new C# script, I used 'KeyValueForLocalization' as the class name. In it, you want to have a public string variable set up so that you can tell the object the "Key" value to find the current language's translation.

using UnityEngine;
using UnityEngine.UI;

public class KeyValueForLocalization : MonoBehaviour {
    public string Key;
    private Text parentGuiText;
    
    void Awake() { 
             parentGuiText = gameObject.GetComponent<Text>();
             parentGuiText.text = UFE.Localization.GetTextValue(Key);
    }
}

Now, you can attach this script to any UI element that has a Text component like the Menu options. You state the Key that element represents and it will update the text value to be whatever is that Language's value.

From there it's just a matter of creating a UI element in the Options menu that calls Localization.ChangeLanguage() to whatever language option you want.

Share

Thumbs up +3 Thumbs down

Re: Language Select from Main Menu or Options?

Thank you so much for this... super helpful! I really appreciate you taking the time to help me.

Share

Thumbs up Thumbs down

8 (edited by MrPonton 2016-09-06 10:45:40)

Re: Language Select from Main Menu or Options?

anthonie121 wrote:

Thank you so much for this... super helpful! I really appreciate you taking the time to help me.

I also forgot that in UFE.cs you want to add a line to instantiate the static LanguageManager Localization:

SetLanguage();

UFE.Localization = LanguageManager.Instance;

switch(UFE.CurrentLanguage) {
      case "Japanese":
            Localization.ChangeLanguage(new SmartCultureInfo("ja-JP", "Japanese", "Japanese", false));
            break;
      default:
            Localization.ChangeLanguage(Localization.defaultLanguage);
            break;
}

I've updated my post to reflect that. If you don't do this you'll get a "NullReferenceException" error when it sets the language.

Share

Thumbs up Thumbs down

9 (edited by MrPonton 2016-09-06 21:31:14)

Re: Language Select from Main Menu or Options?

Noticed another error. In the latest version of UFE the original scripts use 'UFE.config.selectedLanguage.languageName' as the current language setting. Previously this was 'UFE.CurrentLanguage', and currently has no references in the latest version. Now, the selectedLanguage LanguageOption is being called when sending off Alerts in the BattleGUI/ControlScript so that had to be corrected. The SetLanguage() method is what checks for what the selected language of the config is. Also, not sure why, but SmartLocalization right now is being a pain as I can't seem to find the setting to set the defaultLanguage, and it's currently setting it to the language I don't want as default. So I've corrected the switch statement to default to the specific language I want instead of what SmartLocalization's default language is set to.

I've updated my previous post as well.

SetLanguage();

UFE.Localization = LanguageManager.Instance;

switch(UFE.config.selectedLanguage.languageName) {
      case "Japanese":
            Localization.ChangeLanguage(new SmartCultureInfo("ja-JP", "Japanese", "Japanese", false));
            break;
      default:
            Localization.ChangeLanguage(new SmartCultureInfo("en-US", "English", "English", false));
            break;
}

Share

Thumbs up Thumbs down