|
|
(同じ利用者による、間の34版が非表示) |
行1: |
行1: |
− | ==ダウンロード==
| + | [[Unity/多言語化/全体]] |
− | https://learn.unity.com/tutorial/recorded-video-session-localization-tools/?tab=detail#5c7f8528edbc2a002053b671
| + | |
− | <pre>
| + | |
− | LocalizationData.cs
| + | |
− | LocalizationManager.cs
| + | |
− | StartupManager.cs
| + | |
− | LocalizedText.cs
| + | |
− | LocalizedTextEditor.cs
| + | |
− | </pre>
| + | |
| | | |
− | ==翻訳ファイルサンプル==
| + | [[Unity/多言語化/Androidのアプリ名]] |
− | Assets/StreamingAssets/localizedText_ja.json
| + | |
− | <pre>
| + | |
− | {
| + | |
− | "items":[
| + | |
− | {"key":"title","value":"タイトル1"},
| + | |
− | {"key":"edit","value":"編集1"}
| + | |
− | ]
| + | |
− | }
| + | |
− | </pre>
| + | |
− | Assets/StreamingAssets/localizedText_en.json
| + | |
− | <pre>
| + | |
− | {
| + | |
− | "items":[
| + | |
− | {"key":"title","value":"title1"},
| + | |
− | {"key":"edit","value":"edit1"}
| + | |
− | ]
| + | |
− | }
| + | |
− | </pre>
| + | |
| | | |
− | ==上記DLしたファイル設定とカスタマイズ==
| + | [[Unity/多言語化/iOSのアプリ名]] |
− | LocalizationData.cs
| + | |
− | <pre>
| + | |
− | [System.Serializable] | + | |
− | public class LocalizationData
| + | |
− | {
| + | |
− | public LocalizationItem[] items;
| + | |
− | }
| + | |
| | | |
− | [System.Serializable] | + | [[Unity/多言語化/公式多言語]] |
− | public class LocalizationItem
| + | |
− | {
| + | |
− | public string key;
| + | |
− | public string value;
| + | |
− | }
| + | |
− | </pre>
| + | |
− | LocalizationManager.cs
| + | |
− | <pre>
| + | |
− | using System.Collections;
| + | |
− | using System.Collections.Generic;
| + | |
− | using UnityEngine;
| + | |
− | using System.IO;
| + | |
− | | + | |
− | public class LocalizationManager : MonoBehaviour {
| + | |
− | | + | |
− | public static LocalizationManager instance;
| + | |
− | | + | |
− | private Dictionary<string, string> localizedText;
| + | |
− | private bool isReady = false;
| + | |
− | private string missingTextString = "Localized text not found";
| + | |
− | | + | |
− | // Use this for initialization
| + | |
− | void Awake ()
| + | |
− | {
| + | |
− | if (instance == null) {
| + | |
− | instance = this;
| + | |
− | } else if (instance != this)
| + | |
− | {
| + | |
− | Destroy (gameObject);
| + | |
− | }
| + | |
− | | + | |
− | DontDestroyOnLoad (gameObject);
| + | |
− | }
| + | |
− | | + | |
− | public void LoadLocalizedText(string fileName)
| + | |
− | {
| + | |
− | localizedText = new Dictionary<string, string> ();
| + | |
− | string filePath = Path.Combine (Application.streamingAssetsPath, fileName);
| + | |
− | | + | |
− | if (File.Exists (filePath)) {
| + | |
− | string dataAsJson = File.ReadAllText (filePath);
| + | |
− | LocalizationData loadedData = JsonUtility.FromJson<LocalizationData> (dataAsJson);
| + | |
− | | + | |
− | for (int i = 0; i < loadedData.items.Length; i++)
| + | |
− | {
| + | |
− | localizedText.Add (loadedData.items [i].key, loadedData.items [i].value);
| + | |
− | }
| + | |
− | | + | |
− | Debug.Log ("Data loaded, dictionary contains: " + localizedText.Count + " entries");
| + | |
− | } else
| + | |
− | {
| + | |
− | Debug.LogError ("Cannot find file!");
| + | |
− | }
| + | |
− | | + | |
− | isReady = true;
| + | |
− | }
| + | |
− | | + | |
− | public string GetLocalizedValue(string key)
| + | |
− | {
| + | |
− | string result = missingTextString;
| + | |
− | if (localizedText.ContainsKey (key))
| + | |
− | {
| + | |
− | result = localizedText [key];
| + | |
− | }
| + | |
− | | + | |
− | return result;
| + | |
− | | + | |
− | }
| + | |
− | | + | |
− | public bool GetIsReady()
| + | |
− | {
| + | |
− | return isReady;
| + | |
− | }
| + | |
− | | + | |
− | }
| + | |
− | </pre>
| + | |
− | StartupManager.cs
| + | |
− | LocalizedText.cs
| + | |
− | LocalizedTextEditor.cs
| + | |
− | | + | |
− | ==参考==
| + | |
− | https://www.growthsoftware.jp/unity-multilang/
| + | |
− | | + | |
− | https://qiita.com/chocho/items/c32e75bf498d8beec08f
| + | |