Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Giannigiardinelli · May 11, 2020 at 08:20 AM · scripting problemvariablestaticdropdowntranslation

How Translation with a fils txt and script I18n ?

Need to understand this script to translate the game with a txt file

If I make calls to the function

lang = "en";

in the I18n script it works!


 using System;
 using System.Collections.Generic;
 using NUnit.Framework;
 using UnityEngine;
 using UnityEngine.UI;
 
 class I18n
 {
 
     public static Dictionary<String, String> Fields { get; private set; }
     public static string lang;
     /// <summary>
     /// Init on first use
     /// </summary>
     static I18n()
     {
         LoadLanguage();
     }
 
     /// <summary>
     /// Load language files from ressources
     /// </summary>
     private static void LoadLanguage()
     {
 
 
         if (Fields == null)
             Fields = new Dictionary<string, string>();
 
         Fields.Clear();
          lang = Get2LetterISOCodeFromSystemLanguage().ToLower();
 
 
 
         
             lang = "en";       <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
         
         var textAsset = Resources.Load(@"I18n/" + lang); //no .txt needed
         string allTexts = "";
         if (textAsset == null)
             textAsset = Resources.Load(@"I18n/en") as TextAsset; //no .txt needed
         if (textAsset == null)
             Debug.LogError("File not found for I18n: Assets/Resources/I18n/" + lang + ".txt");
         allTexts = (textAsset as TextAsset).text;
         string[] lines = allTexts.Split(new string[] { "\r\n", "\n" },
             StringSplitOptions.None);
         string key, value;
         for (int i = 0; i < lines.Length; i++)
         {
             if (lines[i].IndexOf("=") >= 0 && !lines[i].StartsWith("#"))
             {
                 key = lines[i].Substring(0, lines[i].IndexOf("="));
                 value = lines[i].Substring(lines[i].IndexOf("=") + 1,
                         lines[i].Length - lines[i].IndexOf("=") - 1).Replace("\\n", Environment.NewLine);
                 Fields.Add(key, value);
             }
         }
     }
 
 
     public static string GetLanguage()
     {
         return Get2LetterISOCodeFromSystemLanguage().ToLower();
     }
 
 
     public static string Get2LetterISOCodeFromSystemLanguage()
     {
         SystemLanguage lang = Application.systemLanguage;
         string res = "EN";
         switch (lang)
         {
             case SystemLanguage.Afrikaans: res = "AF"; break;
             case SystemLanguage.Arabic: res = "AR"; break;
             case SystemLanguage.Basque: res = "EU"; break;
             case SystemLanguage.Belarusian: res = "BY"; break;
             case SystemLanguage.Bulgarian: res = "BG"; break;
             case SystemLanguage.Catalan: res = "CA"; break;
             case SystemLanguage.Chinese: res = "ZH"; break;
             case SystemLanguage.ChineseSimplified: res = "ZH"; break;
             case SystemLanguage.ChineseTraditional: res = "ZH"; break;
             case SystemLanguage.Czech: res = "CS"; break;
             case SystemLanguage.Danish: res = "DA"; break;
             case SystemLanguage.Dutch: res = "NL"; break;
             case SystemLanguage.English: res = "EN"; break;
             case SystemLanguage.Estonian: res = "ET"; break;
             case SystemLanguage.Faroese: res = "FO"; break;
             case SystemLanguage.Finnish: res = "FI"; break;
             case SystemLanguage.French: res = "FR"; break;
             case SystemLanguage.German: res = "DE"; break;
             case SystemLanguage.Greek: res = "EL"; break;
             case SystemLanguage.Hebrew: res = "IW"; break;
             case SystemLanguage.Hungarian: res = "HU"; break;
             case SystemLanguage.Icelandic: res = "IS"; break;
             case SystemLanguage.Indonesian: res = "IN"; break;
             case SystemLanguage.Italian: res = "IT"; break;
             case SystemLanguage.Japanese: res = "JA"; break;
             case SystemLanguage.Korean: res = "KO"; break;
             case SystemLanguage.Latvian: res = "LV"; break;
             case SystemLanguage.Lithuanian: res = "LT"; break;
             case SystemLanguage.Norwegian: res = "NO"; break;
             case SystemLanguage.Polish: res = "PL"; break;
             case SystemLanguage.Portuguese: res = "PT"; break;
             case SystemLanguage.Romanian: res = "RO"; break;
             case SystemLanguage.Russian: res = "RU"; break;
             case SystemLanguage.SerboCroatian: res = "SH"; break;
             case SystemLanguage.Slovak: res = "SK"; break;
             case SystemLanguage.Slovenian: res = "SL"; break;
             case SystemLanguage.Spanish: res = "ES"; break;
             case SystemLanguage.Swedish: res = "SV"; break;
             case SystemLanguage.Thai: res = "TH"; break;
             case SystemLanguage.Turkish: res = "TR"; break;
             case SystemLanguage.Ukrainian: res = "UK"; break;
             case SystemLanguage.Unknown: res = "EN"; break;
             case SystemLanguage.Vietnamese: res = "VI"; break;
         }
         //        Debug.Log ("Lang: " + res);
         return res;
     }
 
 }



But if I create another script to make calls for a dropdown where the player selects his language,

it doesn't work!


 using System;
 using System.Collections.Generic;
 using NUnit.Framework;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Options : MonoBehaviour {
 
     public Dropdown DropLangue;
     public GameObject DropDown;
 
 
 
     // Use this for initialization
     void Awake()
     {
 
 
         DropLangue = DropDown.GetComponent<Dropdown>();
     }
 
 
     public void Start()
     {
 
     }
 
     public void Update()
     {
 
     
 
 
         if (DropLangue.value == 0)
         {
             I18n.lang = "en";
         }
 
         if (DropLangue.value == 1)
         {
 
 
     
         }
     }
 }



Why !?

Thank you in advance for helping me and explaining to me!


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

229 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Increasing a score value? 2 Answers

Static Variable Problem 1 Answer

Public and Static Variables 2 Answers

Is it possible to show Static Variables in the Inspector? 10 Answers

Setting static variables in Editor script 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges