Пример #1
0
    static void ImportTranslations()
    {
        string path   = EditorUtility.OpenFilePanel("Load Translation file(csv)", "", "csv");
        int    amount = 0;

        using (StreamReader sr = new StreamReader(path))
        {
            string[] headers = ParseCSVLine(sr.ReadLine());
            while (sr.Peek() != -1)
            {
                string[] values = ParseCSVLine(sr.ReadLine());

                string resName = values[0];

                resName = resName.Substring("Assets/Resources/".Length);
                resName = resName.Substring(0, resName.Length - ".prefab".Length);

                TranslatedText text = Resources.Load(resName, typeof(TranslatedText)) as TranslatedText;

                if (!text)
                {
                    Debug.Log("could not find:" + values[0] + ":" + resName);
                    continue;
                }

                string textToReplace = values[2];

                textToReplace = textToReplace.Replace("\\n", "\n");

                if (text.getText(TranslatedText.LANGUAGES.ENGLISH) != textToReplace)
                {
                    Debug.Log("replacing " + resName);
                    Debug.Log("from:" + text.getText(TranslatedText.LANGUAGES.ENGLISH));
                    Debug.Log("for:" + textToReplace);
                    text.setText(TranslatedText.LANGUAGES.ENGLISH, textToReplace);
                    EditorUtility.SetDirty(text);
                    amount++;
                }
            }
        }

        Debug.Log("imported " + amount + " new strings");
    }
Пример #2
0
    public override void OnInspectorGUI()
    {
        TranslatedText text = (TranslatedText)target;

        GUILayout.Label("Languages", EditorStyles.boldLabel);

        for (int i = 0; i < TranslatedText.LANGUAGES_str.Length; i++)
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(TranslatedText.LANGUAGES_str[i]);
            text.setText((TranslatedText.LANGUAGES)i, EditorGUILayout.TextArea(text.getText((TranslatedText.LANGUAGES)i), GUILayout.Height(64)));
            if (GUI.changed)
            {
                EditorUtility.SetDirty(text);
            }
            GUILayout.EndHorizontal();
        }
    }