Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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 /
This question was closed Jan 10, 2021 at 05:32 PM by viv5552 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by viv5552 · Jan 10, 2021 at 03:06 PM · noobnewbielocalizationlanguageslocale

How to switch language in-game using official unity localization 0.9?

I'm a newbie unity user who has never written a code before starting to learn unity couple weeks ago. Now i'm trying to learn how to implement a localization into game using official unity localization https://docs.unity3d.com/Packages/com.unity.localization@0.9/manual/index.html I've more ol less succesfully assigned different string value for different languages using localization tables. Now i can switch language upon playing the game in editor. But how to switch it in game outside editor? I've tried to create a dropdown with a following script attached: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Localization; using UnityEngine.Localization.Settings;

 public class LanguageDropdown : MonoBehaviour
 {
     private Dropdown dropdown;
     private string identifier;
     void Start()
     {
         dropdown = GetComponent<Dropdown>();
     }
     void Update()
     {
         if (dropdown.value == 0)
         { identifier = "en"; }
         else if (dropdown.value == 1)
         { identifier = "de"; }
         else if (dropdown.value == 2)
         { identifier = "ru"; }
         else if (dropdown.value == 3)
         { identifier = "uk"; }
         SetLanguage(identifier);
         
     }
     void SetLanguage(string identifier)
     { 
         Debug.Log("Selected language: " + identifier);
         LocalizationSettings.SelectLocale(identifier);
 
     }
 }
 

The problem is that a method LocalizationSettings.SelectLocale(); which probably (i'm not sure) should switch current locale is inaccessible due to its protection level. It's defined as protected virtual inside Unity LocalizationSettings class so i cannot access it. So what should i do considering that my scripting skills are very low at the moment?

Comment
Add comment · Show 2
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
avatar image karl_jones ♦♦ · Jan 10, 2021 at 11:40 PM 0
Share

Did you look at the samples that come with the package? There are some examples of language switchers. You can see the samples in the package manager window

avatar image viv5552 karl_jones ♦♦ · Jan 11, 2021 at 08:37 AM 0
Share

Thanks for guidance. I didn't notice them and tried to read manual and scripting API, didn't manage to find answer there and finally stumbled upon a comment to a youtube video which gave the right answer.

1 Reply

  • Sort: 
avatar image
8
Best Answer

Answer by viv5552 · Jan 10, 2021 at 05:31 PM

Turns out it should be done with LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[i];

Comment
Add comment · Show 2 · Share
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
avatar image ashkatchen · Nov 30, 2021 at 09:53 PM 0
Share

Hey dude. Can you walk me through how it's done? I cant figure it out and i cant understand your solution. I'm using Localization 1.0.5

avatar image cocoalovethax ashkatchen · Jan 15 at 04:37 PM 0
Share

This worked for me:

 public void LoadLocale(string languageIdentifier)
         {
             LocalizationSettings settings = LocalizationSettings.Instance;
             LocaleIdentifier localeCode = new LocaleIdentifier(languageIdentifier);//can be "en" "de" "ja" etc.
             for(int i = 0; i < LocalizationSettings.AvailableLocales.Locales.Count; i++)
             {
                 Locale aLocale = LocalizationSettings.AvailableLocales.Locales[i];
                 LocaleIdentifier anIdentifier = aLocale.Identifier;
                 if(anIdentifier == localeCode)
                 {
                     LocalizationSettings.SelectedLocale = aLocale;
                 }
             }
         }

Follow this Question

Answers Answers and Comments

117 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

Related Questions

How to make official localization mix strings with scripted variables? 1 Answer

How to make localization for Dropdown - TextMeshPro? 0 Answers

Best practice to internationalize(I18n) a unity project? 2 Answers

Change gameObject within a Transfom 1 Answer

How to preload language? 0 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