Author Topic: Localization Dictionary?  (Read 4305 times)

Mauri

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Localization Dictionary?
« on: August 25, 2015, 04:07:14 AM »
I'm currently switching from "Daikon Forge GUI" to "NGUI" due to DFGUI's discontinuation and I'm facing a little problem. My entire GUI is multi-language and the script for getting the language from Steam looks like this:

  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using Steamworks;
  4.  
  5. public class SteamLocalization : MonoBehaviour {
  6.    
  7.     // Steam Localization
  8.     // Available Steam language codes:
  9.     // Comment out all currently unsupported languages...
  10.     void Start() {
  11.         if (SteamManager.Initialized) {
  12.             var dict = new Dictionary<string, dfLanguageCode>();
  13.             dict.Add("english", dfLanguageCode.EN);
  14.             dict.Add("german", dfLanguageCode.DE);
  15.             dict.Add("spanish", dfLanguageCode.ES);
  16.             dict.Add("italian", dfLanguageCode.IT);
  17.             dict.Add("french", dfLanguageCode.FR);
  18.             dict.Add("dutch", dfLanguageCode.NL);
  19.             dict.Add("turkish", dfLanguageCode.TR);
  20.            
  21.             var lang = SteamApps.GetCurrentGameLanguage();
  22.            
  23.             try
  24.             {
  25.                 GetComponent<dfLanguageManager>().LoadLanguage(dict[lang]);
  26.                 Debug.Log("Current Language is " + lang);
  27.             }
  28.             catch(KeyNotFoundException)
  29.             {
  30.                 Debug.LogError("Language not found. Setting Language to 'english'. Please run this Application through Steam.");
  31.                 GetComponent<dfLanguageManager>().LoadLanguage(dfLanguageCode.EN);
  32.             }
  33.         }
  34.     }
  35. }
(DFGUI is free nowadays and can be found on GitHub, in case someone wants to test this code)

All translations are stored the same way as NGUI wants them (in a .csv, with "KEY, LANG1, LANG2, ...").


I just don't know how to convert this script to NGUI... I do have read the Localization Documentation page, but no chance :-(

Any idea? :-\

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Localization Dictionary?
« Reply #1 on: August 26, 2015, 12:18:01 PM »
In the future please don't PM me with the same content as your post. I check both at the same time, and having to answer both with copy/paste answers merely wastes my time.

With NGUI you don't need to load localization files. Localization.txt places in the Resources folder is loaded automatically, although you can also do it dynamically if you wish. All languages get loaded from the localization file and become available to use. There is no code needed. I suggest giving the user a choice of language selection, not doing it by country... but if you want to just default to a language. Localization.language = "Whatever" will set the active language.