Hi there,
This is sort of the continuation of [a question I posted yesterday][1]. I am aware that many assets exist in the Unity Assets Store, but I would like to do it myself for knowledge sake and *"just do it, don't let your dreams be dreams"*.
I would like to support localization in my game, and I was mainly inspired by the Android localization format, meaning storing my strings into .xml files and getting them using a Language Loader :
using CustomDictionary = System.Collections.Generic.Dictionary;
using System;
using System.Collections;
using System.IO;
using System.Xml;
public class LanguageLoader {
private CustomDictionary Strings;
private string DefaultString;
public LanguageLoader() {
this.Strings = new CustomDictionary();
this.DefaultString = null;
}
public void Clear() {
this.Strings.Clear();
}
public void Load(string path, string countryCode) {
XmlDocument xmlDocument;
XmlElement rootElement, element;
IEnumerator elementEnumerator;
xmlDocument = new XmlDocument();
try {
xmlDocument.Load(Path.Combine(path, this.GetXmlLanguageFile(countryCode)));
rootElement = xmlDocument.DocumentElement;
if (rootElement == null || !("language".Equals(rootElement.Name)))
throw (new XmlException("Invalid root element !"));
if (!rootElement.GetAttribute("code").Equals(countryCode))
throw (new XmlException("Country codes are different !"));
elementEnumerator = rootElement.GetEnumerator();
while (elementEnumerator.MoveNext()) {
element = (XmlElement) elementEnumerator.Current;
if (element.GetAttribute("name") == null || element.InnerText == null)
throw (new XmlException("Invalid string !"));
this.Strings.Add(element.GetAttribute("name"), element.InnerText);
}
} catch (XmlException exc) {
UnityEngine.Debug.LogException(exc);
}
}
public void SetDefaultString(string defaultString) {
this.DefaultString = defaultString;
}
public string GetXmlLanguageFile(string countryCode) {
return (String.Concat(countryCode.Trim(), ".xml"));
}
public string GetString(string key) {
string returnedString = this.DefaultString;
if (this.Strings.ContainsKey(key))
returnedString = this.Strings[key];
return (returnedString);
}
}
The .xml language file is well stored and I am able to get a string without any problem. My problem is that I don't know how to update my UI correctly when a language is selected by the user. For example, I have a main menu which contains four buttons (see the link above for a visual approach) and these four buttons have to be translated using localization. For this, I made a Menu Manager which contains a function that translates the buttons at start, but I find it really gross :
public void InitializeMainMenu() {
this.MainMenu.transform.Find("Character Demo Button").GetChild(0).gameObject.GetComponent().text = this.Localization.GetString("text_playy_character_demo");
this.MainMenu.transform.Find("Turn-based Demo Button").GetChild(0).gameObject.GetComponent().text = this.Localization.GetString("text_play_turnbased_demo");
this.MainMenu.transform.Find("Languages Button").GetChild(0).gameObject.GetComponent().text = this.Localization.GetString("text_languages_menu");
this.MainMenu.transform.Find("Quit Button").GetChild(0).gameObject.GetComponent().text = this.Localization.GetString("text_quit_game");
this.MainMenu.SetActive(true);
}
The further problem is when the user will select a language : is there any Unity function that updates the GUI once ? I heard about OnGUI() but I feel like this is useless to repeat this code every frame.
I apologize if I can't be more explicit and I'll try to give you more details as the discussion goes.
[1]: http://answers.unity3d.com/questions/1139305/keep-position-of-ui-while-using-horizontal-layout.html
↧
[DIY] Need some help supporting localization on a game and updating UI when a language is selected
↧
How can I check south america SystemLanguage?
Hi
I'm working for localization.
I have European Portuguese, Brazilian Portuguese, European Spanish, South america Spanish text.
But I can not find Brazil Portuguese and South america Spanish in Unity SystemLanguage.
How can I check?
↧
↧
Linking precompiled resources created from resx files
I'm using resx files for localization and I when i compile, the Assets.localized_strings.resources file is generated (at Temp\UnityVS_obj\Debug\Assets.localized_strings.resources) but for some reason at run time it tells me it can't find it with the error :
MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Assets.localized_strings.resources" was correctly embedded or linked into assembly "Assembly-CSharp" at compile time, or that all the satellite assemblies required are loadable and fully signed.
↧
How to localize iOS app name by Unity Cloud build automatically.
How can I localize iOS app name by Unity Cloud build automatically?
I could find some articles that "PostProcessBuild" enable to change "CFBundleDisplayName" but I couldn't do that.
Because most of articles are old information.
My development environment is as follows.
* Windows, Unity5.4.0b21, Unity Cloud build(for iOS build)
Please help me..
↧
Does Unity have Native APK Localization method?
I made a game and translated it to 9 languages (made separate regular C# scripts, which includes static strings)
While uploading APK, Google Play Developer Console shows: "default language only"
How to make Google Play Developer Console indicate APK localization?
Maybe I must put my localization scripts to specific folder, or rename them, or use XML format?....
P.S.
I don't know how to find and modify Android manifest file in Unity. And I don't want to use external plugins from Asset Store.
↧
↧
Language/translation connector to Unity - will it be useful?
Hi guys! We're looking to develop a connector to Unity that will allow translators translate games while playing. Plus there will be a terminology sidebar to check how to correctly input character and item names, so that they are uniform across all strings.
Do you think such a solution will be useful for you?
Is there already something like that?
↧
Best practice to internationalize(I18n) a unity project?
Hi,
I already read many threads about this subject, but all of them was written 2 or 3 years ago.
Does unity integrate a tool to handle internationalization properly?
All the solutions I read suggest loading files manually, parsing txt files, or hardcoding static strings, this looks a bit old fashion.
↧
Localization don't work with the russian text, only english
I make a localization for my game on Unity3d. I have a text file with russian text and file with the same english text. When I try to display rusian text, I can't see it in the game, but english text I can see (if replace russian text to english on the same string). Why is it happens?
![alt text][1]
//===== script 'LoadTextFromFile ' ======
public TextAsset textFileButtonsEng;
public TextAsset textFileButtonsRus;
private string[] dialogLinesButtonsEng;
private string[] dialogLinesButtonsRus;
private int curentLanguageIndex = 1;
void Start()
{
// if file exists
if (textFileButtonsEng && textFileButtonsRus)
{
dialogLinesButtonsEng = (textFileButtonsEng.text.Split("\n"[0]));
dialogLinesButtonsRus = (textFileButtonsRus.text.Split("\n"[0]));
}
}
public string GetLineOfText(string fileName, int lineNumber)
{
switch (fileName)
{
case "tasks":
if (curentLanguageIndex == 0)
return dialogLinesTasksEng[lineNumber];
else if (curentLanguageIndex == 1)
return dialogLinesTasksRus[lineNumber]; break;
}
//========== other script ==========
public Text textTipsTasksComponent;
public LoadTextFromFile loadTextFromFile;
textTipsTasksComponent.text = loadTextFromFile.GetLineOfText("tasks", 25);
It is Arial font and I can see russian text when type it by myself like on the screenshot below.
![alt text][2]
[1]: /storage/temp/78623-nsc4d.jpg
[2]: /storage/temp/78625-lhzyn.jpg
↧
Text in UILabel appears stretched
I have translated a game to Japanese, and for some dynamic labels the texts appears stretched. I am using the font MS Gothic, for other labels is fine. I have tried changing the max width but it appears to have no effect. Any ideas?
↧
↧
Camera Usage Description localization
Hello!
We have been working in an augmented reality app for some time and, since it has been published in several languages, we are trying to localize Unity's Camera Usage Description field. We are using "Smart Localization", an amazing asset to manage languages. I assume that it prevents us from using xCode localization in order to solve the issue.
Did anyone manage to do a similar thing while using a localization asset?
↧
localize many UI texts in one scipt
Hey, I would like to use smart localization(https://www.assetstore.unity3d.com/en/#!/content/7543) to localize a game menu. But I found all the text are written in text component of the button rather than in the strings. Here is what I write to find those text and I was wondering what shall I do next.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Translation : MonoBehaviour {
public Text[] instruction;
// Use this for initialization
void Start()
{
instruction = GetComponentsInChildren();
}
// Update is called once per frame
void Update () {
for (int i=0;i
↧
How to Switch and Display Language on Runtime
I have written a menu to change the language and have my all languages ready. I am using SmartLocalization as the tool. The function to change language (to French, for example) is "LanguageManager.Instance.ChangeLanguage ("fr") . I put this call under void Update() because I think Update() will be called every frame. That's how it looks like in my program.
public void Update() {
LanguageManager.Instance.ChangeLanguage("fr");
}
↧
Which Windows settings determine Application.systemLanguage?
The documentation says "__The language the user's operating system is running in__".
I'm running Windows 10 in English, but Application.systemLanguage keeps reporting 'Dutch' as the language (I'm in the Netherlands, so it's the language of the country I'm in. My region in Windows is normally set to 'Netherlands').
Changing _Region->Location_ and _Region->Administrative->Language for non-Unicode programs_ settings in Windows to United States/English doesn't change anything, Unity keeps reporting that the OS is in Dutch.
So which Windows setting should I change to influence the return value of Application.systemLanguage?
↧
↧
Can we replace Files in already released games
Hello together,
i plan to translate a game that isnt mine ;) but is there a way to just place the translated file in the right directory structure instead packing it into the *.assets file ?
Thanks in advance ^^
↧
Application.systemLanguage returns Unknown for Malay language
I'm localizing my game into multiple languages and Malay is one of them. I see that this is not one of the languages in the SystemLanguage enumeration, so Application.systemLanguage just returns Unknown. This is a problem for me, how can I resolve it? Why does systemLanguage even return an enumeration instead of the name of the language as a string?
Is there any other way I can figure out if the user's device is using the Malay (Bahasa Melayu, etc) language?
↧
Streaming assets android
Hello everyone. I have a problem with streaming assets on mobile devices(On PC everything is good). When I try to find out where is the problem, i discovered, that file couldn`t be found. But why? Help me please. Thanks in advance.
public string languageName = "localizedText_en.json";
public static LocalizationManager instance;
private Dictionary localizedText;
private bool isReady = false;
private string missingTextString = "Localized text not found";
string filePath;
void Awake()
{
if (instance == null)
{
instance = this;
}
else if (instance != this)
{
Destroy(gameObject);
}
DontDestroyOnLoad(gameObject);
}
private void Start()
{
if (PlayerPrefs.GetString("languageName") != "")
languageName = PlayerPrefs.GetString("languageName");
else
languageName = "localizedText_en.json";
Loader(languageName);
}
private void OnLevelWasLoaded()
{
if (PlayerPrefs.GetString("languageName") != "")
languageName = PlayerPrefs.GetString("languageName");
else
languageName = "localizedText_en.json";
Loader(languageName);
}
public void ChangeLanguage(string name)
{
isReady = false;
languageName = name;
PlayerPrefs.SetString("languageName", languageName);
GameObject.Find("FadeManager").GetComponent().TransitionToScene("ProtectEarthGame");
}
public void Loader(string fileName)
{
string filePath = "jar:file://" + Application.dataPath + "!/assets/";
StartCoroutine(LoadLocalizedText(filePath, fileName));
}
public IEnumerator LoadLocalizedText(string path, string fileName)
{
localizedText = new Dictionary();
string filePath = Path.Combine(path, fileName);
WWW www = new WWW(filePath);
yield return www;
string text = www.text;
LocalizationData loadedData = JsonUtility.FromJson(text);
for (int i = 0; i < loadedData.items.Length; i++)
{
localizedText.Add(loadedData.items[i].key, loadedData.items[i].value);
}
isReady = true;
}
↧
Any know where I can find information on how to localize my Asset Offering?
I'd like to offer my Unity Asset Store assets in other countries outside the US, but I've never actually done that and I'm not sure exactly how to go about it. Has anyone done this and can point me in the right direction?
↧
↧
Can i use an iOS default Chinese font instead of including a specific one?
I'm localizing my iOS game in Chinese. I want to avoid including a Chinese TTF font, adding around 40Mo to my app weight (Chinese TTF fonts are very heavy because they contain lot's of signs).
I'm thinking of using an iOS default font like Heiti SC and Heiti TC (source: http://iosfonts.com - on iPhone since iPhone 3), and so set " Include Font Data" to false (source: https://docs.unity3d.com/Manual/class-Font.html).
Has anyone already tried this kind of approach? Does it work? ^_^
↧
How can i avoid to embed a Chinese font in my iOS Game App ?
I have text in chinese in my game app but i don't want to embed a chinese font in the data. Chinese font weight too much. How can i avoid to embed a full chinese font?
↧
Company name localization
I know it's possible to change the app name for the project by using the following xml:Hello World
but is it possible to also change the localization for the COMPANY name?
↧