Beispiel #1
0
 public void UsageAndFunction(int windowId)
 {
     GUILayout.Label("・" + LocalisationFile.GetTranslatedString("UF1"), this.nameStyle);
     GUILayout.Label("・" + LocalisationFile.GetTranslatedString("UF2"), this.nameStyle);
     GUILayout.Label("・" + LocalisationFile.GetTranslatedString("UF3"), this.nameStyle);
     GUILayout.Label("・" + LocalisationFile.GetTranslatedString("UF4"), this.nameStyle);
     GUILayout.Label("・" + LocalisationFile.GetTranslatedString("UF5"), this.nameStyle);
     GUILayout.Label("・" + LocalisationFile.GetTranslatedString("UF6"), this.nameStyle);
     GUI.DragWindow();
 }
Beispiel #2
0
 public void MainWindow(int windowId)
 {
     this.hasCompliance = true;
     this.InspectBlocks();
     GUILayout.FlexibleSpace();
     GUILayout.Space(5f);
     GUILayout.BeginHorizontal();
     this.openURL = GUILayout.Button(LocalisationFile.GetTranslatedString("Link"));
     GUILayout.FlexibleSpace();
     this.playerStats = GUILayout.Toggle(this.playerStats, LocalisationFile.GetTranslatedString("PlayerStats"));
     GUILayout.Space(15f);
     this.uf = GUILayout.Toggle(this.uf, LocalisationFile.GetTranslatedString("UF"));
     GUILayout.Space(15f);
     this.minimise = GUILayout.Toggle(this.minimise, LocalisationFile.GetTranslatedString("Minimise"));
     GUILayout.EndHorizontal();
     GUI.DragWindow(new Rect(0, 0, 10000f, 20f));
 }
Beispiel #3
0
 public override void OnLoad()
 {
     this.mod = new GameObject("Mod4LJT");
     UnityEngine.Object.DontDestroyOnLoad(mod);
     Instance        = this;
     this.resetbound = BoundResetter.Instance;
     UnityEngine.Object.DontDestroyOnLoad(resetbound);
     this.machineInspector = MachineInspector.Instance;
     UnityEngine.Object.DontDestroyOnLoad(machineInspector);
     this.namePlateManager = LJTPlayerLabelManager.Instance;
     UnityEngine.Object.DontDestroyOnLoad(namePlateManager);
     this.blockScriptManager = BlockScriptManager.Instance;
     UnityEngine.Object.DontDestroyOnLoad(blockScriptManager);
     Events.OnBlockInit += this.blockScriptManager.AddBlockScript;
     LocalisationFile.ReadLocalisationFile();
     LJTMessages.CreateMessageTypes();
 }
Beispiel #4
0
 private static void EOL(LocalisationFile localisationFile, StringBuilder builder, int lineNumber)
 {
     localisationFile.mColumns.Add(builder.ToString());
     if (!localisationFile.mRows.ContainsKey(localisationFile.mColumns[0]))
     {
         localisationFile.mRows.Add(localisationFile.mColumns[0], new List <string>(localisationFile.mColumns));
     }
     else
     {
         Debug.Log("String table already contains: " + localisationFile.mColumns[0]);
     }
     if (localisationFile.mColumns.Count != 22)
     {
         Debug.Log("Incorrect number of columns on line: " + lineNumber);
     }
     builder.Length = 0;
     localisationFile.mColumns.Clear();
 }
Beispiel #5
0
        void SetLanguage()
        {
            this.language = OptionsMaster.BesiegeConfig.Language;
            switch (this.language)
            {
            case "English":
            default:
                LocalisationFile.languageInt = 1;
                break;

            case "Japanese":
                LocalisationFile.languageInt = 2;
                break;
            }
            for (int i = 0; i < 6; i++)
            {
                this.translatedNames[i] = LocalisationFile.GetTranslatedString(typeNames[i]);
            }
        }
        private static async Task projectToResX(string projectFile)
        {
            Console.WriteLine($"Converting all localisation files in {projectFile}...");

            MSBuildLocator.RegisterDefaults();

            var workspace = MSBuildWorkspace.Create();
            var project   = await workspace.OpenProjectAsync(projectFile);

            var localisationFiles = project.Documents.Where(d => d.Folders.SequenceEqual(SyntaxTemplates.PROJECT_RELATIVE_LOCALISATION_PATH.Split('/')))
                                    .Where(d => d.Name.EndsWith(".cs"))
                                    .Where(d => Path.GetFileNameWithoutExtension(d.Name).EndsWith(SyntaxTemplates.STRINGS_FILE_SUFFIX))
                                    .ToArray();

            if (localisationFiles.Length == 0)
            {
                Console.WriteLine("No localisation files found in project.");
                return;
            }

            foreach (var file in localisationFiles)
            {
                Console.WriteLine($"Processing {file.Name}...");

                LocalisationFile localisationFile;
                using (var stream = File.OpenRead(file.FilePath))
                    localisationFile = await LocalisationFile.ReadAsync(stream);

                string resxFile = Path.Combine(Path.GetDirectoryName(file.FilePath) !, $"{localisationFile.Prefix}.resx");

                using (var fs = File.Open(resxFile, FileMode.Create, FileAccess.ReadWrite))
                    using (var resWriter = new ResXResourceWriter(fs, getResourceTypeName))
                    {
                        foreach (var member in localisationFile.Members)
                        {
                            resWriter.AddResource(member.Key, member.EnglishText);
                        }
                        resWriter.Generate();
                    }

                Console.WriteLine($"  -> {resxFile}");
            }
        }
Beispiel #7
0
        public static void StartupLanguage()
        {
            string empty = string.Empty;

            empty = CurrentLanguage;
            TextAsset hFFMasterLocalisationFile = HFFResources.instance.HFFMasterLocalisationFile;

            if (hFFMasterLocalisationFile == null)
            {
                Debug.Log("Accessing the language system too early, localisation asset not loaded yet.");
                return;
            }
            sLocalisation             = Load(hFFMasterLocalisationFile.text);
            hFFMasterLocalisationFile = null;
            sInited          = true;
            _CurrentLanguage = empty;
            PlayerPrefs.SetString("Language", empty);
            SetLanguageAndCode(empty, GetLanguageCode(empty));
        }
Beispiel #8
0
 public void StatusWindow(int windowId)
 {
     GUILayout.BeginHorizontal();
     GUILayout.Label(LocalisationFile.GetTranslatedString("Player"), this.defaultStyle, GUILayout.Width(this.labelWidth3));
     GUILayout.Label(LocalisationFile.GetTranslatedString("Machine"), this.defaultStyle, GUILayout.Width(this.labelWidth3));
     GUILayout.Label(LocalisationFile.GetTranslatedString("TankType"), this.defaultStyle, GUILayout.Width(this.labelWidth3));
     GUILayout.Label(LocalisationFile.GetTranslatedString("Compliance"), this.defaultStyle, GUILayout.Width(this.labelWidth3));
     GUILayout.EndHorizontal();
     GUILayout.Space(5f);
     foreach (var kvp in LJTMachine.MachineDic)
     {
         GUILayout.BeginHorizontal();
         GUILayout.Label(kvp.Key.Player.Name, this.defaultStyle, GUILayout.Width(this.labelWidth3));
         GUILayout.Label(kvp.Key.Name, this.defaultStyle, GUILayout.Width(this.labelWidth3));
         GUILayout.Label(LocalisationFile.GetTranslatedString(((TankType)kvp.Value.TankTypeInt).ToString()), this.defaultStyle, GUILayout.Width(this.labelWidth3));
         GUILayout.Label(kvp.Value.HasCompliance ? "OK" : "NO", kvp.Value.HasCompliance ? this.defaultStyle : this.noStyle, GUILayout.Width(this.labelWidth3));
         GUILayout.EndHorizontal();
     }
     GUI.DragWindow();
 }
Beispiel #9
0
        public async Task FileIsNotChangedAfterReSaving()
        {
            await setupLocalisation(
                new LocalisationMember("prop", "property", "property"),
                new LocalisationMember("method", "method", "method",
                                       new LocalisationParameter("int", "i")));

            IFileInfo file    = mockFs.FileInfo.FromFileName(test_file_name);
            string    initial = await mockFs.File.ReadAllTextAsync(file.FullName, CancellationToken.None);

            // Read and re-save via LocalisationFile.
            LocalisationFile localisation;

            using (var stream = file.OpenRead())
                localisation = await LocalisationFile.ReadAsync(stream);
            using (var stream = file.OpenWrite())
                await localisation.WriteAsync(stream, workspace);

            string updated = await mockFs.File.ReadAllTextAsync(file.FullName, CancellationToken.None);

            Assert.Equal(initial, updated);
        }
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocalisationConverter"/> class.
 /// </summary>
 public LocalisationConverter()
 {
     localisationFile = new LocalisationFile();
     xmlManager       = new XmlManager <Localisation>();
 }
Beispiel #11
0
        public void InspectBlocks()
        {
            if (!this.machine)
            {
                GUILayout.Label(LocalisationFile.GetTranslatedString("Caution"), this.defaultStyle);
                return;
            }
            if (!this.minimise)
            {
                GUILayout.Space(5f);
                GUILayout.BeginHorizontal();
                this._tankTypeInt = GUILayout.SelectionGrid(_tankTypeInt, translatedNames, 3);
                if (this._tankTypeInt != (int)this._tankType)
                {
                    this.OnTypeChangeFromGUI(this._tankTypeInt);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(5f);
                GUILayout.BeginHorizontal();
                GUILayout.Label(LocalisationFile.GetTranslatedString("Block"), this.nameStyle, GUILayout.Width(this.labelWidth1));
                GUILayout.Label(LocalisationFile.GetTranslatedString("Minimum"), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.Label(LocalisationFile.GetTranslatedString("Maximum"), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.Label(LocalisationFile.GetTranslatedString("Current"), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.Label(LocalisationFile.GetTranslatedString("Power"), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.Label(LocalisationFile.GetTranslatedString("Judge"), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.EndHorizontal();
                GUILayout.Space(5f);
            }
            foreach (BlockBehaviour BB in this.machine.BuildingBlocks)
            {
                if (!this.restrictedBlocksDic.ContainsKey((int)BB.Prefab.Type))
                {
                    continue;
                }
                this.restrictedBlocksDic[(int)BB.Prefab.Type].currentCount++;
                switch (BB.Prefab.Type)
                {
                case BlockType.Cannon:
                case BlockType.ShrapnelCannon:
                    if (this.restrictedBlocksDic[(int)BB.Prefab.Type].highestPowerValue < (BB as CanonBlock).StrengthSlider.Value)
                    {
                        this.restrictedBlocksDic[(int)BB.Prefab.Type].highestPowerValue = (BB as CanonBlock).StrengthSlider.Value;
                    }
                    continue;

                case BlockType.CogMediumPowered:
                case BlockType.Wheel:
                case BlockType.LargeWheel:
                    if (this.restrictedBlocksDic[(int)BB.Prefab.Type].highestPowerValue < (BB as CogMotorControllerHinge).SpeedSlider.Value)
                    {
                        this.restrictedBlocksDic[(int)BB.Prefab.Type].highestPowerValue = (BB as CogMotorControllerHinge).SpeedSlider.Value;
                    }
                    continue;

                case BlockType.Rocket:
                    if ((BB as TimedRocket).PowerSlider.Value <= 0.5f)
                    {
                        this.restrictedBlocksDic[(int)BB.Prefab.Type].currentCount--;
                    }
                    continue;

                case BlockType.Bomb:
                    if (BB.gameObject.GetComponent <WeakPointBomb>().isWeakPoint)
                    {
                        this.weakPointCount++;
                    }
                    continue;
                }
            }
            foreach (var kvp in this.restrictedBlocksDic)
            {
                int  min;
                int  max;
                int  current;
                bool powerFlag;
                bool judge;
                switch (kvp.Key)
                {
                case (int)BlockType.Propeller:
                    min                 = this.regulation.ChildBlockRestriction[kvp.Key].minNum;
                    max                 = this.regulation.ChildBlockRestriction[kvp.Key].maxNum;
                    current             = kvp.Value.currentCount + this.restrictedBlocksDic[(int)BlockType.SmallPropeller].currentCount;
                    judge               = powerFlag = kvp.Value.highestPowerValue <= this.regulation.ChildBlockRestriction[kvp.Key].maxPowers[0];
                    judge              &= current >= min && current <= max;
                    this.hasCompliance &= judge;
                    if (this.minimise)
                    {
                        continue;
                    }
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(ReferenceMaster.TranslateBlockName((BlockType)kvp.Key).ToUpper(), this.nameStyle, GUILayout.Width(this.labelWidth1));
                    GUILayout.Label(min.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(max.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(current.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Space(this.labelWidth2);
                    GUILayout.Label(judge ? "OK" : "NO", judge ? this.defaultStyle : this.noStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.EndHorizontal();
                    continue;

                case (int)BlockType.SmallPropeller:
                case (int)BlockType.BuildEdge:
                case (int)BlockType.BuildNode:
                    continue;

                case (int)BlockType.Cannon:
                    min     = this.regulation.ChildBlockRestriction[kvp.Key].minNum;
                    max     = this.regulation.ChildBlockRestriction[kvp.Key].maxNum;
                    current = kvp.Value.currentCount;
                    if (current == 0)
                    {
                        judge = powerFlag = kvp.Value.highestPowerValue <= this.regulation.ChildBlockRestriction[kvp.Key].maxPowers[0];
                    }
                    else if (current <= max)
                    {
                        judge = powerFlag = kvp.Value.highestPowerValue <= this.regulation.ChildBlockRestriction[kvp.Key].maxPowers[current - 1];
                    }
                    else
                    {
                        judge = powerFlag = false;
                    }
                    judge &= current >= min;
                    this.hasCompliance &= judge;
                    if (this.minimise)
                    {
                        continue;
                    }
                    GUILayout.BeginHorizontal();
                    GUILayout.Label((ReferenceMaster.TranslateBlockName((BlockType)kvp.Key).ToUpper()), this.nameStyle, GUILayout.Width(this.labelWidth1));
                    GUILayout.Label(min.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(max.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(current.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(powerFlag ? "OK" : "NO", powerFlag ? this.defaultStyle : this.noStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(judge ? "OK" : "NO", judge ? this.defaultStyle : this.noStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.EndHorizontal();
                    continue;

                case (int)BlockType.ShrapnelCannon:
                    min                 = this.regulation.ChildBlockRestriction[kvp.Key].minNum;
                    max                 = this.regulation.ChildBlockRestriction[kvp.Key].maxNum;
                    current             = kvp.Value.currentCount;
                    judge               = powerFlag = kvp.Value.highestPowerValue <= this.regulation.ChildBlockRestriction[kvp.Key].maxPowers[0];
                    judge              &= current >= min && current <= max;
                    this.hasCompliance &= judge;
                    if (this.minimise)
                    {
                        continue;
                    }
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(ReferenceMaster.TranslateBlockName((BlockType)kvp.Key).ToUpper(), this.nameStyle, GUILayout.Width(this.labelWidth1));
                    GUILayout.Label(min.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(max.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(current.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(powerFlag ? "OK" : "NO", powerFlag ? this.defaultStyle : this.noStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(judge ? "OK" : "NO", judge ? this.defaultStyle : this.noStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.EndHorizontal();
                    continue;

                default:
                    min                 = this.regulation.ChildBlockRestriction[kvp.Key].minNum;
                    max                 = this.regulation.ChildBlockRestriction[kvp.Key].maxNum;
                    current             = kvp.Value.currentCount;
                    judge               = powerFlag = kvp.Value.highestPowerValue <= this.regulation.ChildBlockRestriction[kvp.Key].maxPowers[0];
                    judge              &= current >= min && current <= max;
                    this.hasCompliance &= judge;
                    if (this.minimise)
                    {
                        continue;
                    }
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(ReferenceMaster.TranslateBlockName((BlockType)kvp.Key).ToUpper(), this.nameStyle, GUILayout.Width(this.labelWidth1));
                    GUILayout.Label(min.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(max.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.Label(current.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                    if (this.regulation.ChildBlockRestriction[kvp.Key].maxPowers[0] == 0)
                    {
                        GUILayout.Space(this.labelWidth2);
                    }
                    else
                    {
                        GUILayout.Label(powerFlag ? "OK" : "NO", powerFlag ? this.defaultStyle : this.noStyle, GUILayout.Width(this.labelWidth2));
                    }
                    GUILayout.Label(judge ? "OK" : "NO", judge ? this.defaultStyle : this.noStyle, GUILayout.Width(this.labelWidth2));
                    GUILayout.EndHorizontal();
                    continue;
                }
            }
            if (!this.minimise)
            {
                GUILayout.Space(5f);
                GUILayout.BeginHorizontal();
                GUILayout.Label(LocalisationFile.GetTranslatedString("WeakPointBomb"), this.nameStyle, GUILayout.Width(this.labelWidth1));
                GUILayout.Label(1.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.Label(1.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.Label(this.weakPointCount.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.Space(this.labelWidth2);
            }
            bool flag4 = this.weakPointCount == 1;

            this.hasCompliance &= flag4;
            if (!this.minimise)
            {
                GUILayout.Label(flag4 ? "OK" : "NO", flag4 ? this.defaultStyle : this.noStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.EndHorizontal();
                GUILayout.Space(5f);
                GUILayout.BeginHorizontal();
                GUILayout.Label(LocalisationFile.GetTranslatedString("Machine(All)"), this.nameStyle, GUILayout.Width(this.labelWidth1));
                GUILayout.Label(0.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.Label(this.regulation.MaxBlockCount.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.Label(this.machine.DisplayBlockCount.ToString(), this.defaultStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.Space(this.labelWidth2);
            }
            bool flag2 = this.regulation.MaxBlockCount >= this.machine.DisplayBlockCount;

            this.hasCompliance &= flag2;
            if (!this.minimise)
            {
                GUILayout.Label(this.hasCompliance ? "OK" : "NO", this.hasCompliance ? this.defaultStyle : this.noStyle, GUILayout.Width(this.labelWidth2));
                GUILayout.EndHorizontal();
            }
        }
Beispiel #12
0
 public void OnGUI()
 {
     if (StatMaster.SimulationState >= SimulationState.GlobalSimulation || StatMaster.inMenu || StatMaster.isMainMenu || (StatMaster.SimulationState == SimulationState.SpectatorMode && StatMaster.isMP))
     {
         return;
     }
     if (hudToggle)
     {
         foreach (var kvp in this.restrictedBlocksDic)
         {
             kvp.Value.currentCount      = 0;
             kvp.Value.highestPowerValue = 0;
         }
         this.weakPointCount = 0;
         if (StatMaster.isMP)
         {
             LJTMachine.MachineDic[PlayerMachine.GetLocal()].HasCompliance = this.hasCompliance;
         }
         this.windowRect = GUILayout.Window(32575339, this.windowRect, new GUI.WindowFunction(this.MainWindow), LocalisationFile.GetTranslatedString("Title"));
         if (this.uf)
         {
             this.windowRect2 = GUILayout.Window(32575340, this.windowRect2, new GUI.WindowFunction(this.UsageAndFunction), LocalisationFile.GetTranslatedString("UF"));
         }
         if (this.playerStats)
         {
             this.windowRect3 = GUILayout.Window(32575341, this.windowRect3, new GUI.WindowFunction(this.StatusWindow), LocalisationFile.GetTranslatedString("PlayerStats"));
         }
     }
 }
Beispiel #13
0
 private async Task <LocalisationFile> setupFile(string contents)
 {
     mockFs.AddFile(test_file_name, contents);
     using (var stream = mockFs.FileInfo.FromFileName(test_file_name).OpenRead())
         return(await LocalisationFile.ReadAsync(stream));
 }
        private static async Task processPhpFile(string file, string targetDirectory)
        {
            Console.WriteLine($"Processing {file}...");

            var langParts = Regex.Match(file, @"lang[\/\\]([\w-]+)[\/\\](.*)");

            // The language name - en, ro, etc..
            string langName = langParts.Groups[1].Captures[0].Value;

            // Make sure the language name is a standardised IETF language tag. Without this, we run into compiler errors due to case-insensitivity (e.g. pt-br / pt-BR).
            string ietfLangName = CultureInfo.GetCultureInfo(langName).Name;

            // Any sub-directories before the php file itself.
            string subDir = Path.GetDirectoryName(langParts.Groups[2].Captures[0].Value) ?? string.Empty;

            subDir = Path.Combine(subDir.Split(Path.DirectorySeparatorChar).Select(d => d.Pascalize()).ToArray());

            // The full namespace, taking into account any sub-directories from above.
            string subNameSpace = subDir.Replace(Path.DirectorySeparatorChar, '.');
            string nameSpace    = web_namespace;

            if (!string.IsNullOrEmpty(subNameSpace))
            {
                nameSpace += $".{subNameSpace}";
            }

            // The base name of files generated for this language.
            string name = Path.GetFileNameWithoutExtension(file).Pascalize();

            if (langName != en_lang_name)
            {
                name += $".{ietfLangName}";
            }

            // The target directory for files generated for this language.
            targetDirectory = Path.Combine(targetDirectory, subDir);
            Directory.CreateDirectory(targetDirectory); //  Make sure the target directory exists (again, consider sub-directories).

            string targetLocalisationFile = Path.Combine(targetDirectory, $"{name}Strings.cs");
            string targetResourcesFile    = Path.Combine(targetDirectory, $"{name}.resx");

            // The localisation members to generate files from.
            var members = (await getMembersFromPhpFile(file)).ToArray();

            if (members.Length == 0)
            {
                Console.WriteLine("  -> Skipped (empty).");
                return;
            }

            // Print warnings for duplicated keys. For full context, this is done prior to converting keys to lower case.
            var groupedMemberKeys = members.Select(m => m.Key).GroupBy(k => k.ToLowerInvariant());

            foreach (var g in groupedMemberKeys)
            {
                if (g.Count() == 1)
                {
                    continue;
                }

                await printWarning($"  -> WARNING: Skipping duplicate key \"{g.Key}\" ({string.Join(", ", g)}) in {file}.");
            }

            // Convert keys to lower-case and remove duplicates.
            for (int i = 0; i < members.Length; i++)
            {
                members[i] = new LocalisationMember(members[i].Name, members[i].Key.ToLowerInvariant(), members[i].EnglishText, members[i].Parameters.ToArray());
            }
            members = members.Distinct(new LocalisationMemberKeyEqualityComparer()).ToArray();

            // Only create the .cs file for the english localisation.
            if (langName == en_lang_name)
            {
                var localisationFile = new LocalisationFile(nameSpace, Path.GetFileNameWithoutExtension(targetLocalisationFile), name, members);
                using (var fs = File.Open(targetLocalisationFile, FileMode.Create, FileAccess.ReadWrite))
                    await localisationFile.WriteAsync(fs, new AdhocWorkspace());

                Console.WriteLine($"  -> {targetLocalisationFile}");
            }

            // Create the .resx file.
            using (var fs = File.Open(targetResourcesFile, FileMode.Create, FileAccess.ReadWrite))
                using (var resWriter = new ResXResourceWriter(fs, getResourceTypeName))
                {
                    foreach (var member in members)
                    {
                        if (string.IsNullOrEmpty(member.EnglishText) && langName != en_lang_name)
                        {
                            continue;
                        }

                        resWriter.AddResource(member.Key, member.EnglishText);
                    }

                    resWriter.Generate();
                }

            Console.WriteLine($"  -> {targetResourcesFile}");
        }
Beispiel #15
0
        public static LocalisationFile Load(string line)
        {
            int              lineNumber       = 1;
            ProcessMode      processMode      = ProcessMode.kReadChar;
            StringBuilder    stringBuilder    = new StringBuilder(512);
            LocalisationFile localisationFile = new LocalisationFile();
            bool             flag             = false;

            for (int i = 0; i < line.Length; i++)
            {
                switch (processMode)
                {
                case ProcessMode.kSkipLine:
                    if (line[i] != '\r')
                    {
                        if (line[i] == '"')
                        {
                            flag = !flag;
                        }
                        else if (line[i] == '\n' && !flag)
                        {
                            processMode = ProcessMode.kReadChar;
                        }
                    }
                    break;

                case ProcessMode.kReadChar:
                    if (line[i] != '\r')
                    {
                        if (line[i] == '"')
                        {
                            processMode = ProcessMode.kInQuote;
                        }
                        else if (line[i] == ',')
                        {
                            localisationFile.mColumns.Add(stringBuilder.ToString());
                            stringBuilder.Length = 0;
                        }
                        else if (line[i] == '\n')
                        {
                            EOL(localisationFile, stringBuilder, lineNumber);
                        }
                        else
                        {
                            AppendChar(stringBuilder, line[i]);
                        }
                    }
                    break;

                case ProcessMode.kInQuote:
                    if (line[i] == '\r')
                    {
                        break;
                    }
                    if (line[i] == '"')
                    {
                        if (i + 1 < line.Length && line[i + 1] == '"')
                        {
                            i++;
                            AppendChar(stringBuilder, line[i]);
                        }
                        else
                        {
                            processMode = ProcessMode.kReadChar;
                        }
                    }
                    else
                    {
                        AppendChar(stringBuilder, line[i]);
                    }
                    break;
                }
            }
            localisationFile.mColumns.Clear();
            if (localisationFile.mRows.TryGetValue("Key", out localisationFile.mColumns))
            {
                localisationFile.mRows.Remove("Key");
            }
            return(localisationFile);
        }