コード例 #1
0
        public static string Get(string key, Language language)
        {
            var languages = LocalizationImporter.GetLanguages(key);
            var selected  = (int)language;

            if (languages.Count > 0 && selected >= 0 && selected < languages.Count)
            {
                var currentString = languages[selected];
                if (string.IsNullOrEmpty(currentString) || LocalizationImporter.IsLineBreak(currentString))
                {
                    Debug.LogWarning("Could not find key " + key + " for current language " + language + ". Falling back to " + Instance.fallbackLanguage + " with " + languages[(int)Instance.fallbackLanguage]);
                    // EDIT: Cytoid
                    // Default Fujaoese to Simplified Chinese
                    selected      = language == Language.Fujaoese ? (int)Language.Simplified_Chinese : (int)Instance.fallbackLanguage;
                    currentString = languages[selected];
                }

    #if ARABSUPPORT_ENABLED
                if (selected == (int)Language.Arabic)
                {
                    return(ArabicSupport.ArabicFixer.Fix(currentString, instance.showTashkeel, instance.useHinduNumbers));
                }
    #endif

                return(currentString);
            }

            return(string.Format(KeyNotFound, key));
        }
コード例 #2
0
        public static bool KeyExist(string key)
        {
            var languages = LocalizationImporter.GetLanguages(key);
            var selected  = (int)Instance.selectedLanguage;

            return(languages.Count > 0 && Instance.selectedLanguage >= 0 && selected < languages.Count);
        }
コード例 #3
0
        public static string Get(string key, Language language)
        {
            var languages = LocalizationImporter.GetLanguages(key);
            var selected  = (int)language;

            if (languages.Count > 0 && selected >= 0 && selected < languages.Count)
            {
                var currentString = languages[selected];
                if (string.IsNullOrEmpty(currentString) || LocalizationImporter.IsLineBreak(currentString))
                {
                    Debug.LogWarning("Could not find key " + key + " for current language " + language + ". Falling back to " + Instance.fallbackLanguage + " with " + languages[(int)Instance.fallbackLanguage]);
                    selected      = (int)Instance.fallbackLanguage;
                    currentString = languages[selected];
                }

    #if ARABSUPPORT_ENABLED
                if (selected == (int)Language.Arabic)
                {
                    return(ArabicSupport.ArabicFixer.Fix(currentString));
                }
    #endif

                return(currentString);
            }

            return(string.Format(KeyNotFound, key));
        }
コード例 #4
0
        private void DrawAutoComplete(SerializedProperty property)
        {
            var localizedStrings = LocalizationImporter.GetLanguagesStartsWith(property.stringValue);

            if (localizedStrings.Count == 0)
            {
                localizedStrings = LocalizationImporter.GetLanguagesContains(property.stringValue);
            }

            var selectedLanguage = (int)Localization.Instance.SelectedLanguage;

            showAutoComplete.target = EditorGUILayout.Foldout(showAutoComplete.target, "Auto-Complete");
            if (EditorGUILayout.BeginFadeGroup(showAutoComplete.faded))
            {
                EditorGUI.indentLevel++;

                var height = EditorGUIUtility.singleLineHeight * (Mathf.Min(localizedStrings.Count, 6) + 1);
                scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Height(height));
                foreach (var local in localizedStrings)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(local.Key);
                    if (GUILayout.Button(local.Value[selectedLanguage], "CN CountBadge"))
                    {
                        property.stringValue       = local.Key;
                        GUIUtility.hotControl      = 0;
                        GUIUtility.keyboardControl = 0;
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndScrollView();
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndFadeGroup();
        }
コード例 #5
0
        private static void DownloadGoogleSheet(string docsId, string sheetId, LocalizationAssetFormat format, TextAsset textAsset)
        {
            EditorUtility.DisplayCancelableProgressBar("Download", "Downloading...", 0);
            var url = string.Format("https://docs.google.com/spreadsheets/d/{0}/export?format={2}&gid={1}", docsId, sheetId, Enum.GetName(typeof(LocalizationAssetFormat), format).ToLower());

            Debug.Log(url);
#if UNITY_2017_1_OR_NEWER
            var www = UnityWebRequest.Get(url);
            www.SendWebRequest();
#elif UNITY_5_5_OR_NEWER
            var www = UnityWebRequest.Get(url);
            www.Send();
#else
            var www = new WWW(url);
#endif
            while (!www.isDone)
            {
#if UNITY_5_5_OR_NEWER
                var progress = www.downloadProgress;
#else
                var progress = www.progress;
#endif

                if (EditorUtility.DisplayCancelableProgressBar("Download", "Downloading...", progress))
                {
                    return;
                }
            }
            EditorUtility.ClearProgressBar();
            var path = textAsset != null?AssetDatabase.GetAssetPath(textAsset) : null;

            if (string.IsNullOrEmpty(path))
            {
                path = EditorUtility.SaveFilePanelInProject("Save Localization", "", "txt", "Please enter a file name to save the csv to", path);
            }
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

#if UNITY_5_5_OR_NEWER
            var text = www.downloadHandler.text;
#else
            var text = www.text;
#endif

            if (text.StartsWith("<!"))
            {
                Debug.LogError("Google sheet could not be downloaded\n" + text);
                return;
            }

            File.WriteAllText(path, text);

            Debug.Log("Importing " + path);
            AssetDatabase.ImportAsset(path);

            LocalizationImporter.Refresh();
        }
コード例 #6
0
 static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
 {
     for (int index = 0; index < importedAssets.Length; index++)
     {
         var str = importedAssets[index];
         if (str.EndsWith(".csv") && str.Contains("Localization"))
         {
             LocalizationImporter.Refresh();
         }
     }
 }
コード例 #7
0
        /// <summary>
        /// Retreives the correct language string by key.
        /// </summary>
        /// <param name="key">The key string</param>
        /// <returns>A localized string</returns>
        public static string Get(string key)
        {
            var languages = LocalizationImporter.GetLanguages(key);
            var selected  = (int)Instance.selectedLanguage;

            if (languages.Count > 0 && Instance.selectedLanguage >= 0 && selected < languages.Count)
            {
                var currentString = languages[selected];
                if (string.IsNullOrEmpty(currentString) || LocalizationImporter.IsLineBreak(currentString))
                {
                    Debug.LogWarning("Could not find key " + key + " for current language " + Instance.selectedLanguage + ". Falling back to " + Instance.fallbackLanguage + " with " + languages[(int)Instance.fallbackLanguage]);
                    currentString = languages[(int)Instance.fallbackLanguage];
                }
                return(currentString);
            }

            return(string.Format(KeyNotFound, key));
        }
コード例 #8
0
 public static List <string> GetKeys()
 {
     return(LocalizationImporter.GetKeys());
 }
コード例 #9
0
        public override void OnInspectorGUI()
        {
            if (refresh)
            {
                LocalizationImporter.Refresh();
                refresh = false;
            }

            EditorGUI.BeginChangeCheck();
            serializedObject.Update();

            EditorGUILayout.LabelField("Polyglot Localization Settings", (GUIStyle)"IN TitleText");

            var polyglotPath = GetPrefsString(PathPrefs);

            if (string.IsNullOrEmpty(polyglotPath))
            {
                polyglotPath = DefaultPolyglotPath;
            }

            var changed = false;

            if (UpdateTextAsset("polyglotDocument", masterSheet))
            {
                changed     = true;
                masterSheet = null;
            }

            DisplayDocsAndSheetId("Official Polyglot Master", true, false, masterSheet, serializedObject.FindProperty("polyglotDocument"), OfficialSheet, OfficialGId, polyglotPath, DownloadMasterSheet);

            EditorGUILayout.Space();

            if (UpdateTextAsset("customDocument", customSheet))
            {
                changed     = true;
                customSheet = null;
            }

            DisplayDocsAndSheetId("Custom Sheet", false, !ValidateDownloadCustomSheet(), customSheet, serializedObject.FindProperty("customDocument"), GetPrefsString(CustomDocsIdPrefs), GetPrefsString(CustomSheetIdPrefs), GetPrefsString(CustomPathPrefs), DownloadCustomSheet);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Localization Settings", (GUIStyle)"IN TitleText");
            var iterator = serializedObject.GetIterator();

            for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
            {
                if (iterator.propertyPath.Contains("Document"))
                {
                    continue;
                }

#if !ARABSUPPORT_ENABLED
                if (iterator.propertyPath == "Localize")
                {
                    using (new EditorGUI.DisabledGroupScope(true))
                    {
                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Arabic Support", (GUIStyle)"BoldLabel");
                        EditorGUILayout.HelpBox("Enable Arabic Support with ARABSUPPORT_ENABLED post processor flag", MessageType.Info);
                        EditorGUILayout.Toggle(new GUIContent("Show Tashkeel", "Enable Arabic Support with ARABSUPPORT_ENABLED post processor flag"), true);
                        EditorGUILayout.Toggle(new GUIContent("Use Hindu Numbers", "Enable Arabic Support with ARABSUPPORT_ENABLED post processor flag"), false);
                    }
                }
#endif

                using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath))
                    EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]);
            }
#if !ARABSUPPORT_ENABLED
#endif

            serializedObject.ApplyModifiedProperties();
            if (changed || EditorGUI.EndChangeCheck())
            {
                refresh = true;
            }
        }
コード例 #10
0
 private void OnClick()
 {
     StartCoroutine(LocalizationImporter.DownloadPolyglotSheet(UpdateProgressbar));
 }