Пример #1
0
        public static void Generate()
        {
            var text           = FileLoader.LoadDefaultFile().text;
            var lineModels     = CreateLocalizedTextModel(text);
            var duplicatedKeys = GetDuplicatedKeys(lineModels);

            if (duplicatedKeys.Count >= 1)
            {
                string failedKeys = "{";
                foreach (var key in duplicatedKeys)
                {
                    failedKeys = failedKeys + key + ",";
                }
                failedKeys += "}";
                throw new Exception($"Duplicated Key {failedKeys}");
            }

            var header = new LocalizedTextHeaderModel(lineModels[0].LineText);

            var enumCode = ScriptGenerator.GenerateEnumScript(lineModels, header, DefaultEnumName);
            var generatedEnumScriptPath = TargetDefaultOutputFilePath(DefaultEnumName);

            GenerateEnumFile(enumCode, generatedEnumScriptPath);

            var localizerCode = ScriptGenerator.GenerateTextLocalizer(DefaultEnumName);
            var generatedLocalizerScriptPath2 = TargetDefaultOutputFilePath(DefaultTextLocalizerFileName);

            GenerateEnumFile(localizerCode, generatedLocalizerScriptPath2);

            // var uguiTextLocalize = ScriptGenerator.GenerateUGUITextLocalize(DefaultEnumName);
            // var generatedUguiTextLocalize = TargetDefaultOutputFilePath(UGUITextLocalizeFileName);
            // GenerateEnumFile(uguiTextLocalize, generatedUguiTextLocalize);

            AssetDatabase.Refresh();
        }
Пример #2
0
        public static void Generate(string targetLocalizedText, string generatedPath)
        {
            var lineModels     = CreateLocalizedTextModel(targetLocalizedText);
            var duplicatedKeys = GetDuplicatedKeys(lineModels);

            if (duplicatedKeys.Count >= 1)
            {
                string failedKeys = "{";
                foreach (var key in duplicatedKeys)
                {
                    failedKeys = failedKeys + key + ",";
                }
                failedKeys += "}";
                throw new Exception($"Duplicated Key {failedKeys}");
            }

            var header = new LocalizedTextHeaderModel(lineModels[0].LineText);
            var code   = ScriptGenerator.GenerateEnumScript(lineModels, header, DefaultEnumName);

            GenerateEnumFile(code, generatedPath);
            AssetDatabase.Refresh();
        }
Пример #3
0
        public static string GenerateEnumScript(LocalizedTextLineModel[] liveModels, LocalizedTextHeaderModel header, string enumName)
        {
            var builder = new StringBuilder();

            builder.AppendLine("// Auto Generated File");
            builder.AppendLine("// Menu : Tools -> LocalizationEnumGenerate");
            builder.AppendLine("namespace Icarus.Core");
            builder.AppendLine("{");
            builder.AppendLine($"    public enum {enumName}");
            builder.AppendLine("    {");

            for (int i = 0; i < liveModels.Length; i++)
            {
                var line = liveModels[i];
                if (line.Type == LocalizedTextLineType.KeyValue)
                {
                    builder.AppendLine($"        /// <summary>");
                    for (int j = 0; j < line.LocalizedTexts.Length; j++)
                    {
                        builder.AppendLine($"        /// {header.Languages[j]} : {line.LocalizedTexts[j]}");
                    }
                    builder.AppendLine($"        /// </summary>");
                    builder.AppendLine($"        {line.Key},");
                    continue;
                }

                if (line.Type == LocalizedTextLineType.Comment)
                {
                    builder.AppendLine($"        {line.LineText}");
                    continue;
                }
            }

            builder.AppendLine("    }");
            builder.AppendLine("}");
            return(builder.ToString());
        }