[펌] Automatically set Hindi language in Unity
Unity3D/Tips / 2020. 9. 15. 15:55
[추가] Android / iOS 방식이 달라서 플랫폼에 따라 Two Letter ISO 받는 방식을 다르게 적용
/// <summary>
/// Two Letter ISO Language
/// [참조] https://lonewolfonline.net/list-net-culture-country-codes/
/// [참조] https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
/// </summary>
/// <returns></returns>
public static string GetTwoLetterISOLanguage()
{
string strCurrentCultureName = "en";
#if UNITY_EDITOR
strCurrentCultureName = "en";
#elif UNITY_ANDROID
strCurrentCultureName = GetTwoLetterISOLanguage_Android();
#elif UNITY_IOS || UNITY_IPHONE
strCurrentCultureName = GetTwoLetterISOLanguage_iOS();
#endif
return strCurrentCultureName;
}
public static string GetTwoLetterISOLanguage_iOS()
{
string strTwoLetterISOLanguageName = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
Debug.LogFormat("[GetCurrentCultureName_iOS] {0}", strTwoLetterISOLanguageName);
return strTwoLetterISOLanguageName;
}
// returns "en" / "de" / "hi" / "th" / "ar" / ...
public static string GetTwoLetterISOLanguage_Android()
{
#if !UNITY_EDITOR && UNITY_ANDROID
try
{
var locale = new AndroidJavaClass("java.util.Locale");
var localeInst = locale.CallStatic<AndroidJavaObject>("getDefault");
var name = localeInst.Call<string>("getLanguage");
Debug.LogFormat("[getLanguage] {0}", name);
return name;
}
catch (System.Exception e)
{
return "Error";
}
#else
return "Not supported";
#endif
}
// returns "eng" / "deu" / "hin" / ...
public static string GetThreeLetterISOLanguage_Android()
{
#if !UNITY_EDITOR && UNITY_ANDROID
try
{
var locale = new AndroidJavaClass("java.util.Locale");
var localeInst = locale.CallStatic<AndroidJavaObject>("getDefault");
var name = localeInst.Call<string>("getISO3Language");
Debug.LogFormat("[getISO3Language] {0}", name);
return name;
}
catch (System.Exception e)
{
return "Error";
}
#else
return "Not supported";
#endif
}
[출처]
[참조]
You should also be able to use .NET to get the current culture instead:
using System;
using System.Globalization;
using System.Threading;
CultureInfo myCulture = Thread.CurrentThread.CurrentCulture;
// You can then use all these member variables
myCulture.DisplayName
myCulture.EnglishName
myCulture.Name (e.g. es-ES / en-GB)
myCulture.Parent (e.g. es / en)
myCulture.ThreeLetterISOLanguageName (e.g. spa/eng/hin)
myCulture.TwoLetterISOLanguageName (e.g. es/en/hi)
Here's a selection of the Indian 3 and 2 letter ISO codes (see attached jpg)
[출처] forum.unity.com/threads/automatically-set-hindi-language.624973/
반응형
'Unity3D > Tips' 카테고리의 다른 글
[펌] Unity에서 iOS와 Androd 런타임 권한 확인 요구하는 방법 (0) | 2020.10.26 |
---|---|
[Tip] Unity2018 -> Unity2019로 갈 때 obsolate 관련 처리 (1) | 2020.10.06 |
[펌] Sqlite Insert 속도 문제시 (0) | 2020.08.05 |
[펌] [Unity] Android keystore 경로 상대경로로 지정하기 (0) | 2020.06.09 |
[링크] 유니티 프로모션용 영상/동영상 촬영 (0) | 2020.04.03 |