diff --git a/Nitrocid.sln b/Nitrocid.sln index 5f077b197d..aae25d04e4 100644 --- a/Nitrocid.sln +++ b/Nitrocid.sln @@ -57,14 +57,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Tests", "private\N {FD43CAC8-4770-4C63-ABBF-C382D378C02E} = {FD43CAC8-4770-4C63-ABBF-C382D378C02E} EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.LocaleGen", "public\Nitrocid.LocaleGen\Nitrocid.LocaleGen.csproj", "{8EDAE674-CC21-0D06-0641-064C500DE0CC}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Public", "Public", "{A32F9CED-BCDB-48A7-A42D-E98E33BD6E65}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Private", "Private", "{61916ED1-66D6-4938-9F1A-D0DF38D16E20}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.LocaleClean", "private\Nitrocid.LocaleClean\Nitrocid.LocaleClean.csproj", "{22744969-682D-4974-895E-53079DA9EA3C}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Analyzers", "public\Nitrocid.Analyzers\Nitrocid.Analyzers\Nitrocid.Analyzers.csproj", "{511E3B93-C6BF-4DFF-88D1-165FD3BCF428}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Analyzers.CodeFixes", "public\Nitrocid.Analyzers\Nitrocid.Analyzers.CodeFixes\Nitrocid.Analyzers.CodeFixes.csproj", "{92EFB380-0B78-4B92-A227-F0B6BF982F19}" @@ -156,8 +152,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Extras.Diagnostics EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Extras.Crc32", "public\Nitrocid.Addons\Nitrocid.Extras.Crc32\Nitrocid.Extras.Crc32.csproj", "{4CDBC217-C639-4D93-9F9A-FFD5956C0395}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.LocaleTrim", "private\Nitrocid.LocaleTrim\Nitrocid.LocaleTrim.csproj", "{6524403F-F55E-4E8D-8A63-8A7D2FA518D3}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Extras.Md5", "public\Nitrocid.Addons\Nitrocid.Extras.Md5\Nitrocid.Extras.Md5.csproj", "{CE5F80A9-B27E-4D16-AEBB-A09677E63012}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Extras.Sha1", "public\Nitrocid.Addons\Nitrocid.Extras.Sha1\Nitrocid.Extras.Sha1.csproj", "{BB2BCBE2-1F15-4B5F-927F-172B4B7FE9D4}" @@ -203,10 +197,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Generators.KnownAd EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.LocaleChecker", "private\Nitrocid.LocaleChecker\Nitrocid.LocaleChecker.csproj", "{A9DBA465-7F73-449F-B5BD-E143767513E4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.LocaleCheckerStandalone", "private\Nitrocid.LocaleCheckerStandalone\Nitrocid.LocaleCheckerStandalone.csproj", "{73E76BBD-BCFD-4E43-9F17-F937A87A2D1B}" -EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Nitrocid.LocaleCommon", "private\Nitrocid.LocaleCommon\Nitrocid.LocaleCommon.shproj", "{709AC61B-B746-46A7-A5A0-390B9091BE99}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nitrocid.Extras.Chemistry", "public\Nitrocid.Addons\Nitrocid.Extras.Chemistry\Nitrocid.Extras.Chemistry.csproj", "{D7BC8CF1-C12C-435F-BB53-9F0EA4B8EF20}" EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Nitrocid.Analyzers.Common", "public\Nitrocid.Analyzers\Nitrocid.Analyzers.Common\Nitrocid.Analyzers.Common.shproj", "{47D3DE1A-07AB-42A1-BE6E-7F5256B82DD3}" @@ -219,6 +209,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nitrocid.Core", "public\Nit EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Reserved", "Reserved", "{DA50500B-3F8A-4817-842B-40C957416C2C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nitrocid.Locales", "public\Nitrocid.Locales\Nitrocid.Locales.csproj", "{38B58904-50C4-4E0D-A8E7-FD8766D7923C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -233,14 +225,6 @@ Global {2698CB71-9EF6-06A7-2A14-1AFF675F88CB}.Debug|Any CPU.Build.0 = Debug|Any CPU {2698CB71-9EF6-06A7-2A14-1AFF675F88CB}.Release|Any CPU.ActiveCfg = Release|Any CPU {2698CB71-9EF6-06A7-2A14-1AFF675F88CB}.Release|Any CPU.Build.0 = Release|Any CPU - {8EDAE674-CC21-0D06-0641-064C500DE0CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8EDAE674-CC21-0D06-0641-064C500DE0CC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8EDAE674-CC21-0D06-0641-064C500DE0CC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8EDAE674-CC21-0D06-0641-064C500DE0CC}.Release|Any CPU.Build.0 = Release|Any CPU - {22744969-682D-4974-895E-53079DA9EA3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {22744969-682D-4974-895E-53079DA9EA3C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {22744969-682D-4974-895E-53079DA9EA3C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {22744969-682D-4974-895E-53079DA9EA3C}.Release|Any CPU.Build.0 = Release|Any CPU {511E3B93-C6BF-4DFF-88D1-165FD3BCF428}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {511E3B93-C6BF-4DFF-88D1-165FD3BCF428}.Debug|Any CPU.Build.0 = Debug|Any CPU {511E3B93-C6BF-4DFF-88D1-165FD3BCF428}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -397,10 +381,6 @@ Global {4CDBC217-C639-4D93-9F9A-FFD5956C0395}.Debug|Any CPU.Build.0 = Debug|Any CPU {4CDBC217-C639-4D93-9F9A-FFD5956C0395}.Release|Any CPU.ActiveCfg = Release|Any CPU {4CDBC217-C639-4D93-9F9A-FFD5956C0395}.Release|Any CPU.Build.0 = Release|Any CPU - {6524403F-F55E-4E8D-8A63-8A7D2FA518D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6524403F-F55E-4E8D-8A63-8A7D2FA518D3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6524403F-F55E-4E8D-8A63-8A7D2FA518D3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6524403F-F55E-4E8D-8A63-8A7D2FA518D3}.Release|Any CPU.Build.0 = Release|Any CPU {CE5F80A9-B27E-4D16-AEBB-A09677E63012}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CE5F80A9-B27E-4D16-AEBB-A09677E63012}.Debug|Any CPU.Build.0 = Debug|Any CPU {CE5F80A9-B27E-4D16-AEBB-A09677E63012}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -465,10 +445,6 @@ Global {A9DBA465-7F73-449F-B5BD-E143767513E4}.Debug|Any CPU.Build.0 = Debug|Any CPU {A9DBA465-7F73-449F-B5BD-E143767513E4}.Release|Any CPU.ActiveCfg = Release|Any CPU {A9DBA465-7F73-449F-B5BD-E143767513E4}.Release|Any CPU.Build.0 = Release|Any CPU - {73E76BBD-BCFD-4E43-9F17-F937A87A2D1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {73E76BBD-BCFD-4E43-9F17-F937A87A2D1B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {73E76BBD-BCFD-4E43-9F17-F937A87A2D1B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {73E76BBD-BCFD-4E43-9F17-F937A87A2D1B}.Release|Any CPU.Build.0 = Release|Any CPU {D7BC8CF1-C12C-435F-BB53-9F0EA4B8EF20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D7BC8CF1-C12C-435F-BB53-9F0EA4B8EF20}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7BC8CF1-C12C-435F-BB53-9F0EA4B8EF20}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -485,6 +461,10 @@ Global {2617CFBB-4AF9-48DB-B2A7-7BEAF8575011}.Debug|Any CPU.Build.0 = Debug|Any CPU {2617CFBB-4AF9-48DB-B2A7-7BEAF8575011}.Release|Any CPU.ActiveCfg = Release|Any CPU {2617CFBB-4AF9-48DB-B2A7-7BEAF8575011}.Release|Any CPU.Build.0 = Release|Any CPU + {38B58904-50C4-4E0D-A8E7-FD8766D7923C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {38B58904-50C4-4E0D-A8E7-FD8766D7923C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {38B58904-50C4-4E0D-A8E7-FD8766D7923C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {38B58904-50C4-4E0D-A8E7-FD8766D7923C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -492,8 +472,6 @@ Global GlobalSection(NestedProjects) = preSolution {C7B37899-C361-423D-9512-FE0A87A46866} = {A32F9CED-BCDB-48A7-A42D-E98E33BD6E65} {2698CB71-9EF6-06A7-2A14-1AFF675F88CB} = {D5693E90-DBB5-4C20-B83B-A200CEB8A639} - {8EDAE674-CC21-0D06-0641-064C500DE0CC} = {804E124D-5B66-4F40-BB98-776CD386E618} - {22744969-682D-4974-895E-53079DA9EA3C} = {5427F963-3094-4111-AB05-DAE364A8DF67} {511E3B93-C6BF-4DFF-88D1-165FD3BCF428} = {60986DC6-07C5-40D1-A305-741E8ABE39FC} {92EFB380-0B78-4B92-A227-F0B6BF982F19} = {60986DC6-07C5-40D1-A305-741E8ABE39FC} {A9D16C17-745F-467E-854F-A5C40A28D7A9} = {60986DC6-07C5-40D1-A305-741E8ABE39FC} @@ -538,7 +516,6 @@ Global {C83EB703-1DE7-48C9-9406-1CFA5140235F} = {B60F276A-FE12-4001-916E-080344ED1FD9} {47BECAD8-5DB2-4DE1-B0F0-3225E3396AF7} = {B60F276A-FE12-4001-916E-080344ED1FD9} {4CDBC217-C639-4D93-9F9A-FFD5956C0395} = {B60F276A-FE12-4001-916E-080344ED1FD9} - {6524403F-F55E-4E8D-8A63-8A7D2FA518D3} = {5427F963-3094-4111-AB05-DAE364A8DF67} {CE5F80A9-B27E-4D16-AEBB-A09677E63012} = {B60F276A-FE12-4001-916E-080344ED1FD9} {BB2BCBE2-1F15-4B5F-927F-172B4B7FE9D4} = {B60F276A-FE12-4001-916E-080344ED1FD9} {600337A5-0D56-476A-9428-52B1EF665950} = {B60F276A-FE12-4001-916E-080344ED1FD9} @@ -558,24 +535,20 @@ Global {E403EE05-8642-4496-8897-CBD762D7670B} = {61916ED1-66D6-4938-9F1A-D0DF38D16E20} {E1B8ED9D-541A-4D9E-AAF5-2671114E179B} = {E403EE05-8642-4496-8897-CBD762D7670B} {A9DBA465-7F73-449F-B5BD-E143767513E4} = {5427F963-3094-4111-AB05-DAE364A8DF67} - {73E76BBD-BCFD-4E43-9F17-F937A87A2D1B} = {5427F963-3094-4111-AB05-DAE364A8DF67} - {709AC61B-B746-46A7-A5A0-390B9091BE99} = {5427F963-3094-4111-AB05-DAE364A8DF67} {D7BC8CF1-C12C-435F-BB53-9F0EA4B8EF20} = {B60F276A-FE12-4001-916E-080344ED1FD9} {47D3DE1A-07AB-42A1-BE6E-7F5256B82DD3} = {60986DC6-07C5-40D1-A305-741E8ABE39FC} {0F9E07AB-70DC-4305-9406-34465BB0B0D8} = {B60F276A-FE12-4001-916E-080344ED1FD9} {E47A4664-21AD-4D05-85A5-9E3D86A9AC45} = {DA50500B-3F8A-4817-842B-40C957416C2C} {2617CFBB-4AF9-48DB-B2A7-7BEAF8575011} = {DA50500B-3F8A-4817-842B-40C957416C2C} {DA50500B-3F8A-4817-842B-40C957416C2C} = {A32F9CED-BCDB-48A7-A42D-E98E33BD6E65} + {38B58904-50C4-4E0D-A8E7-FD8766D7923C} = {804E124D-5B66-4F40-BB98-776CD386E618} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {424D8E7A-CFEB-40AE-A79C-437D603177FD} EndGlobalSection GlobalSection(SharedMSBuildProjectFiles) = preSolution - private\Nitrocid.LocaleCommon\Nitrocid.LocaleCommon.projitems*{22744969-682d-4974-895e-53079da9ea3c}*SharedItemsImports = 5 + public\Nitrocid.Analyzers\Nitrocid.Analyzers.Common\Nitrocid.Analyzers.Common.projitems*{38b58904-50c4-4e0d-a8e7-fd8766d7923c}*SharedItemsImports = 5 public\Nitrocid.Analyzers\Nitrocid.Analyzers.Common\Nitrocid.Analyzers.Common.projitems*{47d3de1a-07ab-42a1-be6e-7f5256b82dd3}*SharedItemsImports = 13 - private\Nitrocid.LocaleCommon\Nitrocid.LocaleCommon.projitems*{6524403f-f55e-4e8d-8a63-8a7d2fa518d3}*SharedItemsImports = 5 - private\Nitrocid.LocaleCommon\Nitrocid.LocaleCommon.projitems*{709ac61b-b746-46a7-a5a0-390b9091be99}*SharedItemsImports = 13 - public\Nitrocid.Analyzers\Nitrocid.Analyzers.Common\Nitrocid.Analyzers.Common.projitems*{73e76bbd-bcfd-4e43-9f17-f937a87a2d1b}*SharedItemsImports = 5 public\Nitrocid.Analyzers\Nitrocid.Analyzers.Common\Nitrocid.Analyzers.Common.projitems*{df07f4e1-47b2-452d-a200-f15f558c4977}*SharedItemsImports = 5 EndGlobalSection EndGlobal diff --git a/assets/ks-jl b/assets/ks-jl index 431e75d7c6..472b3d0555 100644 --- a/assets/ks-jl +++ b/assets/ks-jl @@ -17,10 +17,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -if [ -e "/usr/lib/ks/Nitrocid.LocaleGen.dll" ]; then - dotnet "/usr/lib/ks/Nitrocid.LocaleGen.dll" $@ -elif [ -e "./Nitrocid.LocaleGen.dll" ]; then - dotnet "./Nitrocid.LocaleGen.dll" $@ +if [ -e "/usr/lib/ks/Nitrocid.Locales.dll" ]; then + dotnet "/usr/lib/ks/Nitrocid.Locales.dll" $@ +elif [ -e "./Nitrocid.Locales.dll" ]; then + dotnet "./Nitrocid.Locales.dll" $@ else echo "Unable to find the entry point." fi diff --git a/assets/ks-jl.1 b/assets/ks-jl.1 index b6093e23e7..eff182ce63 100644 --- a/assets/ks-jl.1 +++ b/assets/ks-jl.1 @@ -15,13 +15,13 @@ .\" along with this program. If not, see . .\" -.TH ks\-jl 1 "23 Feb 2024" "0.1.0" "Nitrocid KS - Nitrocid.LocaleGen" +.TH ks\-jl 1 "4 Jan 2025" "0.1.0" "Nitrocid KS - Nitrocid.Locales" .SH NAME -ks\-jl \- Locale Generator for Nitrocid KS +ks\-jl \- Locale Tools for Nitrocid KS .SH SYNOPSIS ks\-jl [args] .SH DESCRIPTION -ks\-jl is the Nitrocid KS locale jsonifier that converts the language text files (whether default or custom) to the JSON format that Nitrocid KS can read. +ks\-jl is the Nitrocid KS locale manager that allows you to manage various operations for the localization system. .SH DOCUMENTATION The whole documentation can be found in https://aptivi.gitbook.io/nitrocid-ks-manual. .SH AUTHOR diff --git a/assets/ks-jl.cmd b/assets/ks-jl.cmd index 5d66e8cc9d..ba82f1f67c 100644 --- a/assets/ks-jl.cmd +++ b/assets/ks-jl.cmd @@ -20,4 +20,4 @@ REM along with this program. If not, see . REM This script runs Nitrocid KS JL. This is a shortcut for running REM KS-JL so that you don't have to write the full name of the executable. set ROOTPATH=%~dp0 -dotnet "%ROOTPATH%Nitrocid.LocaleGen.dll" %* +dotnet "%ROOTPATH%Nitrocid.Locales.dll" %* diff --git a/private/Nitrocid.LocaleCheckerStandalone/Nitrocid.LocaleCheckerStandalone.csproj b/private/Nitrocid.LocaleCheckerStandalone/Nitrocid.LocaleCheckerStandalone.csproj deleted file mode 100644 index 0c585ce5b5..0000000000 --- a/private/Nitrocid.LocaleCheckerStandalone/Nitrocid.LocaleCheckerStandalone.csproj +++ /dev/null @@ -1,48 +0,0 @@ - - - - Debug - AnyCPU - {DF07F4E1-47B2-452D-A200-F15F558C4977} - Exe - AnyCPU - true - true - Nitrocid.LocaleCheckerStandalone - Nitrocid.LocaleCheckerStandalone - Nitrocid KS Locale Checker - Nitrocid KS Locale Checker - ../../public/Nitrocid/OfficialAppIcon-NitrocidKS.ico - - - - - - true - - - false - true - - - - - - - - - - - - - - - - - - - - - - - diff --git a/private/Nitrocid.LocaleClean/Analyzers/LocalizableResourcesAnalyzer.cs b/private/Nitrocid.LocaleClean/Analyzers/LocalizableResourcesAnalyzer.cs deleted file mode 100644 index 54dffc9f84..0000000000 --- a/private/Nitrocid.LocaleClean/Analyzers/LocalizableResourcesAnalyzer.cs +++ /dev/null @@ -1,94 +0,0 @@ -// -// Nitrocid KS Copyright (C) 2018-2025 Aptivi -// -// This file is part of Nitrocid KS -// -// Nitrocid KS is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Nitrocid KS is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace Nitrocid.LocaleClean.Analyzers -{ - internal static class LocalizableResourcesAnalyzer - { - internal static string[] GetLocalizedStrings() - { - List localizedStrings = []; - - // Open every resource except the English translations file - var resourceNames = EntryPoint.thisAssembly.GetManifestResourceNames().Except([ - "Nitrocid.LocaleClean.eng.json", - ]); - foreach (var resourceName in resourceNames) - { - // Open the resource and load it to a JSON token instance - var stream = EntryPoint.thisAssembly.GetManifestResourceStream(resourceName) ?? - throw new Exception($"Opening the {resourceName} resource stream has failed."); - var reader = new StreamReader(stream); - var jsonReader = new JsonTextReader(reader); - var document = JToken.Load(jsonReader) ?? - throw new Exception($"Unable to parse JSON for {resourceName}."); - - // Determine if this is a theme or a settings entries list - var themeMetadata = document.Type == JTokenType.Array ? null : document["Metadata"]; - if (themeMetadata is not null) - { - // It's a theme. Get its description and its localizable boolean value - string description = ((string?)themeMetadata["Description"] ?? "").Replace("\\\"", "\""); - bool localizable = (bool?)themeMetadata["Localizable"] ?? false; - if (!string.IsNullOrEmpty(description) && localizable && EntryPoint.localizationList.Contains(description)) - localizedStrings.Add(description); - } - else if (document.Type == JTokenType.Array) - { - // It's likely a settings entry list, but verify - foreach (var settingsEntryList in document) - { - // Check the description and the display - string description = ((string?)settingsEntryList["Desc"] ?? "").Replace("\\\"", "\""); - string displayAs = ((string?)settingsEntryList["DisplayAs"] ?? "").Replace("\\\"", "\""); - string knownAddonDisplay = ((string?)settingsEntryList["display"] ?? "").Replace("\\\"", "\""); - if (!string.IsNullOrEmpty(description) && EntryPoint.localizationList.Contains(description)) - localizedStrings.Add(description); - if (!string.IsNullOrEmpty(displayAs) && EntryPoint.localizationList.Contains(displayAs)) - localizedStrings.Add(displayAs); - if (!string.IsNullOrEmpty(knownAddonDisplay) && EntryPoint.localizationList.Contains(knownAddonDisplay)) - localizedStrings.Add(knownAddonDisplay); - - // Now, check the keys - JArray? keys = (JArray?)settingsEntryList["Keys"]; - if (keys is null || keys.Count == 0) - continue; - foreach (var key in keys) - { - string keyName = ((string?)key["Name"] ?? "").Replace("\\\"", "\""); - string keyDesc = ((string?)key["Description"] ?? "").Replace("\\\"", "\""); - if (!string.IsNullOrEmpty(keyName) && EntryPoint.localizationList.Contains(keyName)) - localizedStrings.Add(keyName); - if (!string.IsNullOrEmpty(keyDesc) && EntryPoint.localizationList.Contains(keyDesc)) - localizedStrings.Add(keyDesc); - } - } - } - } - return [.. localizedStrings]; - } - } -} diff --git a/private/Nitrocid.LocaleClean/Analyzers/ReverseNLOC0001.cs b/private/Nitrocid.LocaleClean/Analyzers/ReverseNLOC0001.cs deleted file mode 100644 index cd85988359..0000000000 --- a/private/Nitrocid.LocaleClean/Analyzers/ReverseNLOC0001.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -// Nitrocid KS Copyright (C) 2018-2025 Aptivi -// -// This file is part of Nitrocid KS -// -// Nitrocid KS is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Nitrocid KS is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Nitrocid.LocaleClean.Analyzers -{ - internal class ReverseNLOC0001 : IAnalyzer - { - public bool Analyze(Document document, out string[] localized) - { - localized = []; - var tree = document.GetSyntaxTreeAsync().Result; - if (tree is null) - return false; - var syntaxNodeNodes = tree.GetRoot().DescendantNodesAndSelf().OfType().ToList(); - bool found = false; - List localizedStrings = []; - foreach (var syntaxNode in syntaxNodeNodes) - { - // Check for argument - if (syntaxNode is not InvocationExpressionSyntax exp) - continue; - var args = exp.ArgumentList.Arguments; - if (args.Count < 1) - continue; - var localizableStringArgument = args[0] ?? - throw new Exception("Can't get localizable string"); - - // Now, check for the Translate.DoTranslation() call - if (exp.Expression is not MemberAccessExpressionSyntax expMaes) - continue; - if (expMaes.Expression is IdentifierNameSyntax expIdentifier && expMaes.Name is IdentifierNameSyntax identifier) - { - // Verify that we're dealing with Translate.DoTranslation() - var location = syntaxNode.GetLocation(); - var idExpression = expIdentifier.Identifier.Text; - var idName = identifier.Identifier.Text; - if (idExpression == "Translate" && idName == "DoTranslation") - { - // Now, get the string representation from the argument count and compare it with the list of translations. - // You'll notice that we sometimes call Translate.DoTranslation() with a variable instead of a string, so - // check that first, because they're usually obtained from a string representation usually prefixed with - // either the /* Localizable */ comment or in individual kernel resources. However, the resources don't - // have a prefix, so the key names alone are enough. - if (localizableStringArgument.Expression is LiteralExpressionSyntax literalText) - { - string text = literalText.ToString(); - text = text[1..^1].Replace("\\\"", "\""); - if (EntryPoint.localizationList.Contains(text)) - { - found = true; - localizedStrings.Add(text); - } - } - } - } - } - localized = [.. localizedStrings]; - return found; - } - } -} diff --git a/private/Nitrocid.LocaleClean/Analyzers/ReverseNLOC0001Implicit.cs b/private/Nitrocid.LocaleClean/Analyzers/ReverseNLOC0001Implicit.cs deleted file mode 100644 index ec2add0f0c..0000000000 --- a/private/Nitrocid.LocaleClean/Analyzers/ReverseNLOC0001Implicit.cs +++ /dev/null @@ -1,105 +0,0 @@ -// -// Nitrocid KS Copyright (C) 2018-2025 Aptivi -// -// This file is part of Nitrocid KS -// -// Nitrocid KS is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Nitrocid KS is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using System.Collections.Generic; -using System.Linq; - -namespace Nitrocid.LocaleClean.Analyzers -{ - internal class ReverseNLOC0001Implicit : IAnalyzer - { - public bool Analyze(Document document, out string[] localized) - { - localized = []; - var tree = document.GetSyntaxTreeAsync().Result; - if (tree is null) - return false; - var syntaxNodeNodes = tree.GetRoot().DescendantNodesAndSelf().OfType().ToList(); - bool found = false; - List localizedStrings = []; - foreach (var syntaxNode in syntaxNodeNodes) - { - // Check for argument - if (syntaxNode is not CompilationUnitSyntax exp) - continue; - var triviaList = exp.DescendantTrivia(); - var multiLineComments = triviaList.Where((trivia) => trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)); - foreach (var multiLineComment in multiLineComments) - { - string comment = multiLineComment.ToString(); - if (comment == "/* Localizable */") - { - // We found a localizable string, but we need to find the string itself, so get all the possible - // tokens. - var node = exp.FindNode(multiLineComment.Span); - var tokens = node.DescendantTokens() - .Where(token => token.GetAllTrivia() - .Where((trivia) => trivia.IsKind(SyntaxKind.MultiLineCommentTrivia) && trivia.ToString() == "/* Localizable */").Any()); - - // Now, enumerate them to find the string - foreach (var token in tokens) - { - void Process(LiteralExpressionSyntax literalText) - { - // Process it. - var location = literalText.GetLocation(); - string text = literalText.ToString(); - text = text.Substring(1, text.Length - 2).Replace("\\\"", "\""); - if (EntryPoint.localizationList.Contains(text)) - { - found = true; - localizedStrings.Add(text); - } - } - - // Try to get a child - int start = token.FullSpan.End; - var parent = token.Parent; - if (parent is null) - continue; - if (parent is LiteralExpressionSyntax literalParent) - { - Process(literalParent); - continue; - } - if (parent is NameColonSyntax) - parent = parent.Parent; - if (parent is null) - continue; - var child = (SyntaxNode?)parent.ChildThatContainsPosition(start); - if (child is null) - continue; - - // Now, check to see if it's a literal string - if (child is LiteralExpressionSyntax literalText) - Process(literalText); - else if (child is ArgumentSyntax argument && argument.Expression is LiteralExpressionSyntax literalArgText) - Process(literalArgText); - } - } - } - } - localized = [.. localizedStrings]; - return found; - } - } -} diff --git a/private/Nitrocid.LocaleClean/AnalyzersList.cs b/private/Nitrocid.LocaleClean/AnalyzersList.cs deleted file mode 100644 index bd955e3a57..0000000000 --- a/private/Nitrocid.LocaleClean/AnalyzersList.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -// Nitrocid KS Copyright (C) 2018-2025 Aptivi -// -// This file is part of Nitrocid KS -// -// Nitrocid KS is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Nitrocid KS is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - - -// -// Nitrocid KS Copyright (C) 2018-2025 Aptivi -// -// This file is part of Nitrocid KS -// -// Nitrocid KS is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Nitrocid KS is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -using Nitrocid.LocaleClean.Analyzers; - -namespace Nitrocid.LocaleClean -{ - internal static class AnalyzersList - { - // For contributors: If you're going to add a new analyzer, you need to copy the implementation from Analyzers to here, - // and make a dedicated diagnostic class for the standalone analyzer to recognize your new analyzer. - internal static readonly IAnalyzer[] analyzers = - [ - new ReverseNLOC0001(), - new ReverseNLOC0001Implicit(), - ]; - } -} diff --git a/private/Nitrocid.LocaleClean/Nitrocid.LocaleClean.csproj b/private/Nitrocid.LocaleClean/Nitrocid.LocaleClean.csproj deleted file mode 100644 index ae953d8a52..0000000000 --- a/private/Nitrocid.LocaleClean/Nitrocid.LocaleClean.csproj +++ /dev/null @@ -1,48 +0,0 @@ - - - - Debug - AnyCPU - {DF07F4E1-47B2-452D-A200-F15F558C4977} - Exe - AnyCPU - true - true - Nitrocid.LocaleClean - Nitrocid.LocaleClean - Nitrocid KS Locale Cleaner - Nitrocid KS Locale Cleaner - ../../public/Nitrocid/OfficialAppIcon-NitrocidKS.ico - - - - - - true - - - false - true - - - - - - - - - - - - - - - - - - - - - - - diff --git a/private/Nitrocid.LocaleClean/Properties/launchSettings.json b/private/Nitrocid.LocaleClean/Properties/launchSettings.json deleted file mode 100644 index 7ecf5fc921..0000000000 --- a/private/Nitrocid.LocaleClean/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "Nitrocid.LocaleClean": { - "commandName": "Project" - }, - "Nitrocid.LocaleClean - Dry": { - "commandName": "Project", - "commandLineArgs": "-dry" - } - } -} \ No newline at end of file diff --git a/private/Nitrocid.LocaleCommon/CodeLister.cs b/private/Nitrocid.LocaleCommon/CodeLister.cs deleted file mode 100644 index 48b2d58e73..0000000000 --- a/private/Nitrocid.LocaleCommon/CodeLister.cs +++ /dev/null @@ -1,91 +0,0 @@ -// -// Nitrocid KS Copyright (C) 2018-2025 Aptivi -// -// This file is part of Nitrocid KS -// -// Nitrocid KS is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Nitrocid KS is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -using System.Collections.Generic; -using System.IO; - -namespace Nitrocid.LocaleCommon -{ - internal static class CodeLister - { - private static string[] ListCodeFilesForKS() - { - // Check to see if we have the Nitrocid KS folder - string kernelSimulatorSource = "../../../../../public/Nitrocid/"; - string kernelSimulatorAddonsSource = "../../../../../public/Nitrocid.Addons/"; - List sources = []; - if (Directory.Exists(kernelSimulatorSource)) - { - // Iterate through all the source files for Nitrocid KS - string[] files = Directory.GetFiles(kernelSimulatorSource, "*.cs", SearchOption.AllDirectories); - sources.AddRange(files); - } - if (Directory.Exists(kernelSimulatorAddonsSource)) - { - // Iterate through all the source files for Nitrocid KS addons - string[] files = Directory.GetFiles(kernelSimulatorAddonsSource, "*.cs", SearchOption.AllDirectories); - sources.AddRange(files); - } - return [.. sources]; - } - - private static string[] ListDataFilesForKS() - { - // Check to see if we have the Nitrocid KS folder - string kernelSimulatorDataSource = "../../../../../public/Nitrocid/Resources/Settings/"; - string kernelSimulatorDataAddonsSource = "../../../../../public/Nitrocid.Addons/"; - List data = []; - if (Directory.Exists(kernelSimulatorDataSource)) - { - // Iterate through all the data files for Nitrocid KS - string[] files = Directory.GetFiles(kernelSimulatorDataSource, "*Entries.json", SearchOption.AllDirectories); - data.AddRange(files); - } - if (Directory.Exists(kernelSimulatorDataAddonsSource)) - { - // Iterate through all the data files for Nitrocid KS - string[] files = Directory.GetFiles(kernelSimulatorDataAddonsSource, "*Settings.json", SearchOption.AllDirectories); - data.AddRange(files); - } - return [.. data]; - } - - internal static List<(string, string)> PopulateSources() - { - List<(string, string)> sources = []; - - // List all code files to add the sources - foreach (string source in ListCodeFilesForKS()) - sources.Add((source, File.ReadAllText(source))); - - return sources; - } - - internal static List<(string, string)> PopulateData() - { - List<(string, string)> sources = []; - - // List all code files to add the sources - foreach (string source in ListDataFilesForKS()) - sources.Add((source, File.ReadAllText(source))); - - return sources; - } - } -} diff --git a/private/Nitrocid.LocaleCommon/Nitrocid.LocaleCommon.projitems b/private/Nitrocid.LocaleCommon/Nitrocid.LocaleCommon.projitems deleted file mode 100644 index 79b46d33a0..0000000000 --- a/private/Nitrocid.LocaleCommon/Nitrocid.LocaleCommon.projitems +++ /dev/null @@ -1,16 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - 709ac61b-b746-46a7-a5a0-390b9091be99 - - - Nitrocid.LocaleCommon - - - - - - - \ No newline at end of file diff --git a/private/Nitrocid.LocaleCommon/Nitrocid.LocaleCommon.shproj b/private/Nitrocid.LocaleCommon/Nitrocid.LocaleCommon.shproj deleted file mode 100644 index 42cd1d5bb7..0000000000 --- a/private/Nitrocid.LocaleCommon/Nitrocid.LocaleCommon.shproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - 709ac61b-b746-46a7-a5a0-390b9091be99 - 14.0 - - - - - - - - diff --git a/private/Nitrocid.LocaleTrim/Nitrocid.LocaleTrim.csproj b/private/Nitrocid.LocaleTrim/Nitrocid.LocaleTrim.csproj deleted file mode 100644 index 30cb00ceb1..0000000000 --- a/private/Nitrocid.LocaleTrim/Nitrocid.LocaleTrim.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - Exe - AnyCPU - - - - true - true - true - - - false - true - true - - - - - - - diff --git a/private/Nitrocid.LocaleTrim/Properties/launchSettings.json b/private/Nitrocid.LocaleTrim/Properties/launchSettings.json deleted file mode 100644 index 31021c7512..0000000000 --- a/private/Nitrocid.LocaleTrim/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "Nitrocid.LocaleTrim": { - "commandName": "Project" - }, - "Nitrocid.LocaleTrim - Dry": { - "commandName": "Project", - "commandLineArgs": "-dry" - } - } -} \ No newline at end of file diff --git a/public/Nitrocid.Addons/Nitrocid.Extras.LanguageStudio/Studio/LanguageStudioApp.cs b/public/Nitrocid.Addons/Nitrocid.Extras.LanguageStudio/Studio/LanguageStudioApp.cs index 78cba06ebd..767cf0ce5a 100644 --- a/public/Nitrocid.Addons/Nitrocid.Extras.LanguageStudio/Studio/LanguageStudioApp.cs +++ b/public/Nitrocid.Addons/Nitrocid.Extras.LanguageStudio/Studio/LanguageStudioApp.cs @@ -27,7 +27,6 @@ using Nitrocid.Files.Paths; using Nitrocid.Kernel.Debugging; using Nitrocid.Languages; -using Nitrocid.LocaleGen.Core.Serializer; using System.Collections.Generic; using System.Linq; using Textify.General; @@ -36,6 +35,7 @@ using Terminaux.Inputs.Interactive; using Terminaux.Inputs.Styles; using System; +using Terminaux.Inputs.Styles.Infobox; namespace Nitrocid.Extras.LanguageStudio.Studio { @@ -171,7 +171,7 @@ public static void StartLanguageStudio(string pathToTranslations, bool useTui = if (selectedStringNum == englishLines.Count + 1) { // User chose to make a new string. - string newString = InputTools.ReadLine(Translate.DoTranslation("Enter a new string") + ": "); + string newString = InfoBoxInputColor.WriteInfoBoxInput(Translate.DoTranslation("Enter a new string") + ": "); englishLines.Add(newString); foreach (var translatedLang in translatedLines.Keys) translatedLines[translatedLang].Add(translatedLang == "eng" ? newString : "???"); @@ -192,8 +192,8 @@ public static void StartLanguageStudio(string pathToTranslations, bool useTui = } else if (selectedStringNum == englishLines.Count + 3) { - // User chose to save the translations. Invoke LocaleGen for this. - TextWriterColor.Write(Translate.DoTranslation("Saving language...")); + // User chose to save the translations. + InfoBoxNonModalColor.WriteInfoBox(Translate.DoTranslation("Saving language...")); foreach (var translatedLine in translatedLines) { string language = translatedLine.Key; @@ -201,7 +201,7 @@ public static void StartLanguageStudio(string pathToTranslations, bool useTui = string languagePath = $"{pathToTranslations}/{language}.txt"; FilesystemTools.WriteContents(languagePath, [.. localizations]); } - LanguageGenerator.GenerateLocaleFiles(pathToTranslations); + InfoBoxModalColor.WriteInfoBoxModal(Translate.DoTranslation("Done! Please use the Nitrocid.Locales application with appropriate arguments to finalize the languages. You can use this path:") + $" {pathToTranslations}"); } else if (selectedStringNum == englishLines.Count + 4 || selectedStringNum == -1) { @@ -242,7 +242,7 @@ private static void HandleStringTranslation(List strings, int index, str // Try to get a language and prompt the user for the translation string selectedLang = targetLanguages[selectedLangNum - 1]; - string translated = InputTools.ReadLine(Translate.DoTranslation("Write your translation of") + $" \"{str}\": "); + string translated = InfoBoxInputColor.WriteInfoBoxInput(Translate.DoTranslation("Write your translation of") + $" \"{str}\": "); translatedLines[selectedLang][index] = translated; } } diff --git a/public/Nitrocid.Addons/Nitrocid.Extras.LanguageStudio/Studio/LanguageStudioCli.cs b/public/Nitrocid.Addons/Nitrocid.Extras.LanguageStudio/Studio/LanguageStudioCli.cs index e7db30df51..1cb939c6f4 100644 --- a/public/Nitrocid.Addons/Nitrocid.Extras.LanguageStudio/Studio/LanguageStudioCli.cs +++ b/public/Nitrocid.Addons/Nitrocid.Extras.LanguageStudio/Studio/LanguageStudioCli.cs @@ -20,7 +20,6 @@ using System.Collections.Generic; using Nitrocid.Files; using Nitrocid.Languages; -using Nitrocid.LocaleGen.Core.Serializer; using Terminaux.Inputs.Interactive; using Terminaux.Inputs.Styles.Infobox; @@ -110,7 +109,7 @@ internal void Save() string languagePath = $"{pathToTranslations}/{language}.txt"; FilesystemTools.WriteContents(languagePath, [.. localizations]); } - LanguageGenerator.GenerateLocaleFiles(pathToTranslations); + InfoBoxModalColor.WriteInfoBoxModal(Translate.DoTranslation("Done! Please use the Nitrocid.Locales application with appropriate arguments to finalize the languages. You can use this path:") + $" {pathToTranslations}"); } } } diff --git a/public/Nitrocid.LocaleGen/Generator.cs b/public/Nitrocid.LocaleGen/Generator.cs deleted file mode 100644 index a133801f88..0000000000 --- a/public/Nitrocid.LocaleGen/Generator.cs +++ /dev/null @@ -1,123 +0,0 @@ -// -// Nitrocid KS Copyright (C) 2018-2025 Aptivi -// -// This file is part of Nitrocid KS -// -// Nitrocid KS is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Nitrocid KS is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -using System; -using System.Collections.Generic; -using System.IO; -using Nitrocid.ConsoleBase.Colors; -using Nitrocid.ConsoleBase.Writers; -using Terminaux.Writer.ConsoleWriters; -using Nitrocid.LocaleGen.Core.Serializer; -using Terminaux.Base.Checks; - -namespace Nitrocid.LocaleGen -{ - internal static class Generator - { - - /// - /// Entry point - /// - public static void Main(string[] Args) - { - // Check console - ConsoleChecker.CheckConsole(); - - // Parse for arguments - var arguments = new List(); - var switches = new List(); - bool custom = true; - bool addon = true; - bool normal = true; - bool dry = false; - var copyToResources = false; - string toSearch = ""; - if (Args.Length > 0) - { - // Separate between switches and arguments - foreach (string Arg in Args) - { - if (Arg.StartsWith("--")) - { - // It's a switch. - switches.Add(Arg); - } - else - { - // It's an argument. - arguments.Add(Arg); - } - } - - // Change the values of custom and normal to match the switches provided - custom = switches.Contains("--CustomOnly") || switches.Contains("--All"); - normal = switches.Contains("--NormalOnly") || switches.Contains("--All"); - addon = switches.Contains("--AddonOnly") || switches.Contains("--All"); - copyToResources = switches.Contains("--CopyToResources"); - dry = switches.Contains("--Dry"); - - // Check to see if we're going to parse one language - bool singular = switches.Contains("--Singular"); - if (singular & arguments.Count > 0) - { - // Select the language to be searched - toSearch = arguments[0]; - } - else if (singular) - { - // We can't be singular without providing the language! - TextWriters.Write("Provide a language to generate.", true, KernelColorType.Error); - Environment.Exit(1); - } - - // Check to see if we're going to show help - if (switches.Contains("--Help")) - { - TextWriterColor.Write("{0} [--CustomOnly|--NormalOnly|--All|--Singular|--CopyToResources|--Dry|--Help]", Path.GetFileName(Environment.GetCommandLineArgs()[0])); - Environment.Exit(1); - } - } - - try - { - // Get the translation folders - string translations = Path.GetFullPath("Translations"); - string translationsAddon = Path.GetFullPath("AddonTranslations"); - string customs = Path.GetFullPath("CustomLanguages"); - - // Warn if dry - if (dry) - TextWriters.Write("Running in dry mode. No changes will be made. Take out the --Dry switch if you really want to apply changes. Look at the debug window.", true, KernelColorType.Warning); - - // Now, do the job! - if (normal) - LanguageGenerator.GenerateLocaleFiles(translations, toSearch, copyToResources, dry); - if (addon) - LanguageGenerator.GenerateLocaleFiles(translationsAddon, toSearch, copyToResources, dry); - if (custom) - LanguageGenerator.GenerateLocaleFiles(customs, toSearch, copyToResources, dry); - } - catch (Exception ex) - { - TextWriters.Write("Unexpected error in converter:" + $" {ex.Message}", true, KernelColorType.Error); - TextWriters.Write(ex.StackTrace ?? "No stack trace!", true, KernelColorType.Error); - } - } - } -} diff --git a/public/Nitrocid.LocaleGen/Nitrocid.LocaleGen.csproj b/public/Nitrocid.LocaleGen/Nitrocid.LocaleGen.csproj deleted file mode 100644 index af66691233..0000000000 --- a/public/Nitrocid.LocaleGen/Nitrocid.LocaleGen.csproj +++ /dev/null @@ -1,80 +0,0 @@ - - - - Debug - AnyCPU - {8EDAE674-CC21-0D06-0641-064C500DE0CC} - Exe - AnyCPU - true - true - Nitrocid.LocaleGen.Generator - Nitrocid.LocaleGen - Nitrocid.LocaleGen - ..\Nitrocid\KSBuild\ - Nitrocid KS Locale Generator - Nitrocid KS Locale Generator - ../Nitrocid/OfficialAppIcon-NitrocidKS.ico - - - - - - true - - - false - true - - - - - - - {c7b37899-c361-423d-9512-fe0a87a46866} - Nitrocid - - - - - - - - Always - - - Always - - - Always - - - Always - - - Always - - - - - - - - Always - - - Always - - - - - - - - - - - - - - diff --git a/public/Nitrocid.LocaleGen/Properties/launchSettings.json b/public/Nitrocid.LocaleGen/Properties/launchSettings.json deleted file mode 100644 index 532bc148b2..0000000000 --- a/public/Nitrocid.LocaleGen/Properties/launchSettings.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "profiles": { - "Nitrocid.LocaleGen - Copy localizations to resources": { - "commandName": "Project", - "commandLineArgs": "--CopyToResources --All" - }, - "Nitrocid.LocaleGen": { - "commandName": "Project" - }, - "Nitrocid.LocaleGen - Dry": { - "commandName": "Project", - "commandLineArgs": "--Dry --All" - }, - "Nitrocid.LocaleGen - Dry & Copy to resources": { - "commandName": "Project", - "commandLineArgs": "--Dry --CopyToResources --All" - }, - "Nitrocid.LocaleGen - Dry & Custom Only": { - "commandName": "Project", - "commandLineArgs": "--Dry --CustomOnly" - }, - "Nitrocid.LocaleGen - Dry & Normal Only": { - "commandName": "Project", - "commandLineArgs": "--Dry --NormalOnly" - }, - "Nitrocid.LocaleGen - Dry & Addon Only": { - "commandName": "Project", - "commandLineArgs": "--Dry --AddonOnly" - } - } -} \ No newline at end of file diff --git a/private/Nitrocid.LocaleCheckerStandalone/Analyzers/IAnalyzer.cs b/public/Nitrocid.Locales/Actions/Analyzers/IAnalyzer.cs similarity index 88% rename from private/Nitrocid.LocaleCheckerStandalone/Analyzers/IAnalyzer.cs rename to public/Nitrocid.Locales/Actions/Analyzers/IAnalyzer.cs index 08f014d787..26d9ad02f8 100644 --- a/private/Nitrocid.LocaleCheckerStandalone/Analyzers/IAnalyzer.cs +++ b/public/Nitrocid.Locales/Actions/Analyzers/IAnalyzer.cs @@ -19,10 +19,11 @@ using Microsoft.CodeAnalysis; -namespace Nitrocid.LocaleCheckerStandalone.Analyzers +namespace Nitrocid.Locales.Actions.Analyzers { internal interface IAnalyzer { bool Analyze(Document document, out string[] unlocalized); + bool ReverseAnalyze(Document document, out string[] localized); } } diff --git a/private/Nitrocid.LocaleCheckerStandalone/Analyzers/LocalizableResourcesAnalyzer.cs b/public/Nitrocid.Locales/Actions/Analyzers/LocalizableResourcesAnalyzer.cs similarity index 56% rename from private/Nitrocid.LocaleCheckerStandalone/Analyzers/LocalizableResourcesAnalyzer.cs rename to public/Nitrocid.Locales/Actions/Analyzers/LocalizableResourcesAnalyzer.cs index 4c1cab7cf3..d23684d25b 100644 --- a/private/Nitrocid.LocaleCheckerStandalone/Analyzers/LocalizableResourcesAnalyzer.cs +++ b/public/Nitrocid.Locales/Actions/Analyzers/LocalizableResourcesAnalyzer.cs @@ -26,17 +26,25 @@ using Terminaux.Colors.Data; using Terminaux.Writer.ConsoleWriters; -namespace Nitrocid.LocaleCheckerStandalone.Analyzers +namespace Nitrocid.Locales.Actions.Analyzers { internal static class LocalizableResourcesAnalyzer { + // For contributors: If you're going to add a new analyzer, you need to copy the implementation from Analyzers to here, + // and make a dedicated diagnostic class for the standalone analyzer to recognize your new analyzer. + internal static readonly IAnalyzer[] analyzers = + [ + new NLOC0001(), + new NLOC0001Implicit(), + ]; + internal static string[] GetUnlocalizedStrings() { List unlocalizedStrings = []; // Open every resource except the English translations file var resourceNames = EntryPoint.thisAssembly.GetManifestResourceNames().Except([ - "Nitrocid.LocaleCheckerStandalone.eng.json", + "Nitrocid.Locales.eng.json", ]); foreach (var resourceName in resourceNames) { @@ -55,7 +63,7 @@ internal static string[] GetUnlocalizedStrings() // It's a theme. Get its description and its localizable boolean value string description = ((string?)themeMetadata["Description"] ?? "").Replace("\\\"", "\""); bool localizable = (bool?)themeMetadata["Localizable"] ?? false; - if (!string.IsNullOrEmpty(description) && localizable && !EntryPoint.localizationList.Contains(description)) + if (!string.IsNullOrEmpty(description) && localizable && !Checker.localizationList.Contains(description)) { TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized theme description found: {description}", true, ConsoleColors.Yellow); unlocalizedStrings.Add(description); @@ -70,17 +78,17 @@ internal static string[] GetUnlocalizedStrings() string description = ((string?)settingsEntryList["Desc"] ?? "").Replace("\\\"", "\""); string displayAs = ((string?)settingsEntryList["DisplayAs"] ?? "").Replace("\\\"", "\""); string knownAddonDisplay = ((string?)settingsEntryList["display"] ?? "").Replace("\\\"", "\""); - if (!string.IsNullOrEmpty(description) && !EntryPoint.localizationList.Contains(description)) + if (!string.IsNullOrEmpty(description) && !Checker.localizationList.Contains(description)) { TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized settings description found: {description}", true, ConsoleColors.Yellow); unlocalizedStrings.Add(description); } - if (!string.IsNullOrEmpty(displayAs) && !EntryPoint.localizationList.Contains(displayAs)) + if (!string.IsNullOrEmpty(displayAs) && !Checker.localizationList.Contains(displayAs)) { TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized settings display found: {displayAs}", true, ConsoleColors.Yellow); unlocalizedStrings.Add(displayAs); } - if (!string.IsNullOrEmpty(knownAddonDisplay) && !EntryPoint.localizationList.Contains(knownAddonDisplay)) + if (!string.IsNullOrEmpty(knownAddonDisplay) && !Checker.localizationList.Contains(knownAddonDisplay)) { TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized known addon display found: {knownAddonDisplay}", true, ConsoleColors.Yellow); unlocalizedStrings.Add(knownAddonDisplay); @@ -94,12 +102,12 @@ internal static string[] GetUnlocalizedStrings() { string keyName = ((string?)key["Name"] ?? "").Replace("\\\"", "\""); string keyDesc = ((string?)key["Description"] ?? "").Replace("\\\"", "\""); - if (!string.IsNullOrEmpty(keyName) && !EntryPoint.localizationList.Contains(keyName)) + if (!string.IsNullOrEmpty(keyName) && !Checker.localizationList.Contains(keyName)) { TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized key name found: {keyName}", true, ConsoleColors.Yellow); unlocalizedStrings.Add(keyName); } - if (!string.IsNullOrEmpty(keyDesc) && !EntryPoint.localizationList.Contains(keyDesc)) + if (!string.IsNullOrEmpty(keyDesc) && !Checker.localizationList.Contains(keyDesc)) { TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized key description found: {keyDesc}", true, ConsoleColors.Yellow); unlocalizedStrings.Add(keyDesc); @@ -110,5 +118,68 @@ internal static string[] GetUnlocalizedStrings() } return [.. unlocalizedStrings]; } + + internal static string[] GetLocalizedStrings() + { + List localizedStrings = []; + + // Open every resource except the English translations file + var resourceNames = EntryPoint.thisAssembly.GetManifestResourceNames().Except([ + "Nitrocid.Locales.eng.json", + ]); + foreach (var resourceName in resourceNames) + { + // Open the resource and load it to a JSON token instance + var stream = EntryPoint.thisAssembly.GetManifestResourceStream(resourceName) ?? + throw new Exception($"Opening the {resourceName} resource stream has failed."); + var reader = new StreamReader(stream); + var jsonReader = new JsonTextReader(reader); + var document = JToken.Load(jsonReader) ?? + throw new Exception($"Unable to parse JSON for {resourceName}."); + + // Determine if this is a theme or a settings entries list + var themeMetadata = document.Type == JTokenType.Array ? null : document["Metadata"]; + if (themeMetadata is not null) + { + // It's a theme. Get its description and its localizable boolean value + string description = ((string?)themeMetadata["Description"] ?? "").Replace("\\\"", "\""); + bool localizable = (bool?)themeMetadata["Localizable"] ?? false; + if (!string.IsNullOrEmpty(description) && localizable && Cleaner.localizationList.Contains(description)) + localizedStrings.Add(description); + } + else if (document.Type == JTokenType.Array) + { + // It's likely a settings entry list, but verify + foreach (var settingsEntryList in document) + { + // Check the description and the display + string description = ((string?)settingsEntryList["Desc"] ?? "").Replace("\\\"", "\""); + string displayAs = ((string?)settingsEntryList["DisplayAs"] ?? "").Replace("\\\"", "\""); + string knownAddonDisplay = ((string?)settingsEntryList["display"] ?? "").Replace("\\\"", "\""); + if (!string.IsNullOrEmpty(description) && Cleaner.localizationList.Contains(description)) + localizedStrings.Add(description); + if (!string.IsNullOrEmpty(displayAs) && Cleaner.localizationList.Contains(displayAs)) + localizedStrings.Add(displayAs); + if (!string.IsNullOrEmpty(knownAddonDisplay) && Cleaner.localizationList.Contains(knownAddonDisplay)) + localizedStrings.Add(knownAddonDisplay); + + // Now, check the keys + JArray? keys = (JArray?)settingsEntryList["Keys"]; + if (keys is null || keys.Count == 0) + continue; + foreach (var key in keys) + { + string keyName = ((string?)key["Name"] ?? "").Replace("\\\"", "\""); + string keyDesc = ((string?)key["Description"] ?? "").Replace("\\\"", "\""); + if (!string.IsNullOrEmpty(keyName) && Cleaner.localizationList.Contains(keyName)) + localizedStrings.Add(keyName); + if (!string.IsNullOrEmpty(keyDesc) && Cleaner.localizationList.Contains(keyDesc)) + localizedStrings.Add(keyDesc); + } + } + } + } + return [.. localizedStrings]; + } } } diff --git a/private/Nitrocid.LocaleCheckerStandalone/Analyzers/NLOC0001.cs b/public/Nitrocid.Locales/Actions/Analyzers/NLOC0001.cs similarity index 56% rename from private/Nitrocid.LocaleCheckerStandalone/Analyzers/NLOC0001.cs rename to public/Nitrocid.Locales/Actions/Analyzers/NLOC0001.cs index f92ceaf8cb..863e68fa39 100644 --- a/private/Nitrocid.LocaleCheckerStandalone/Analyzers/NLOC0001.cs +++ b/public/Nitrocid.Locales/Actions/Analyzers/NLOC0001.cs @@ -24,7 +24,7 @@ using System.Collections.Generic; using System.Linq; -namespace Nitrocid.LocaleCheckerStandalone.Analyzers +namespace Nitrocid.Locales.Actions.Analyzers { internal class NLOC0001 : IAnalyzer { @@ -68,7 +68,7 @@ public bool Analyze(Document document, out string[] unlocalized) { string text = literalText.ToString(); text = text[1..^1].Replace("\\\"", "\""); - if (!EntryPoint.localizationList.Contains(text)) + if (!Checker.localizationList.Contains(text)) { AnalyzerTools.PrintFromLocation(location, document, GetType(), $"Unlocalized string found: {text}"); found = true; @@ -81,5 +81,58 @@ public bool Analyze(Document document, out string[] unlocalized) unlocalized = [.. unlocalizedStrings]; return found; } + + public bool ReverseAnalyze(Document document, out string[] localized) + { + localized = []; + var tree = document.GetSyntaxTreeAsync().Result; + if (tree is null) + return false; + var syntaxNodeNodes = tree.GetRoot().DescendantNodesAndSelf().OfType().ToList(); + bool found = false; + List localizedStrings = []; + foreach (var syntaxNode in syntaxNodeNodes) + { + // Check for argument + if (syntaxNode is not InvocationExpressionSyntax exp) + continue; + var args = exp.ArgumentList.Arguments; + if (args.Count < 1) + continue; + var localizableStringArgument = args[0] ?? + throw new Exception("Can't get localizable string"); + + // Now, check for the Translate.DoTranslation() call + if (exp.Expression is not MemberAccessExpressionSyntax expMaes) + continue; + if (expMaes.Expression is IdentifierNameSyntax expIdentifier && expMaes.Name is IdentifierNameSyntax identifier) + { + // Verify that we're dealing with Translate.DoTranslation() + var location = syntaxNode.GetLocation(); + var idExpression = expIdentifier.Identifier.Text; + var idName = identifier.Identifier.Text; + if (idExpression == "Translate" && idName == "DoTranslation") + { + // Now, get the string representation from the argument count and compare it with the list of translations. + // You'll notice that we sometimes call Translate.DoTranslation() with a variable instead of a string, so + // check that first, because they're usually obtained from a string representation usually prefixed with + // either the /* Localizable */ comment or in individual kernel resources. However, the resources don't + // have a prefix, so the key names alone are enough. + if (localizableStringArgument.Expression is LiteralExpressionSyntax literalText) + { + string text = literalText.ToString(); + text = text[1..^1].Replace("\\\"", "\""); + if (Cleaner.localizationList.Contains(text)) + { + found = true; + localizedStrings.Add(text); + } + } + } + } + } + localized = [.. localizedStrings]; + return found; + } } } diff --git a/private/Nitrocid.LocaleCheckerStandalone/Analyzers/NLOC0001Implicit.cs b/public/Nitrocid.Locales/Actions/Analyzers/NLOC0001Implicit.cs similarity index 55% rename from private/Nitrocid.LocaleCheckerStandalone/Analyzers/NLOC0001Implicit.cs rename to public/Nitrocid.Locales/Actions/Analyzers/NLOC0001Implicit.cs index 3e2636e9b9..fb9c71006d 100644 --- a/private/Nitrocid.LocaleCheckerStandalone/Analyzers/NLOC0001Implicit.cs +++ b/public/Nitrocid.Locales/Actions/Analyzers/NLOC0001Implicit.cs @@ -24,7 +24,7 @@ using System.Collections.Generic; using System.Linq; -namespace Nitrocid.LocaleCheckerStandalone.Analyzers +namespace Nitrocid.Locales.Actions.Analyzers { internal class NLOC0001Implicit : IAnalyzer { @@ -65,7 +65,7 @@ void Process(LiteralExpressionSyntax literalText) var location = literalText.GetLocation(); string text = literalText.ToString(); text = text.Substring(1, text.Length - 2).Replace("\\\"", "\""); - if (!EntryPoint.localizationList.Contains(text)) + if (!Checker.localizationList.Contains(text)) { AnalyzerTools.PrintFromLocation(location, document, GetType(), $"Unlocalized string found: {text}"); found = true; @@ -103,5 +103,80 @@ void Process(LiteralExpressionSyntax literalText) unlocalized = [.. unlocalizedStrings]; return found; } + + public bool ReverseAnalyze(Document document, out string[] localized) + { + localized = []; + var tree = document.GetSyntaxTreeAsync().Result; + if (tree is null) + return false; + var syntaxNodeNodes = tree.GetRoot().DescendantNodesAndSelf().OfType().ToList(); + bool found = false; + List localizedStrings = []; + foreach (var syntaxNode in syntaxNodeNodes) + { + // Check for argument + if (syntaxNode is not CompilationUnitSyntax exp) + continue; + var triviaList = exp.DescendantTrivia(); + var multiLineComments = triviaList.Where((trivia) => trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)); + foreach (var multiLineComment in multiLineComments) + { + string comment = multiLineComment.ToString(); + if (comment == "/* Localizable */") + { + // We found a localizable string, but we need to find the string itself, so get all the possible + // tokens. + var node = exp.FindNode(multiLineComment.Span); + var tokens = node.DescendantTokens() + .Where(token => token.GetAllTrivia() + .Where((trivia) => trivia.IsKind(SyntaxKind.MultiLineCommentTrivia) && trivia.ToString() == "/* Localizable */").Any()); + + // Now, enumerate them to find the string + foreach (var token in tokens) + { + void Process(LiteralExpressionSyntax literalText) + { + // Process it. + var location = literalText.GetLocation(); + string text = literalText.ToString(); + text = text.Substring(1, text.Length - 2).Replace("\\\"", "\""); + if (Cleaner.localizationList.Contains(text)) + { + found = true; + localizedStrings.Add(text); + } + } + + // Try to get a child + int start = token.FullSpan.End; + var parent = token.Parent; + if (parent is null) + continue; + if (parent is LiteralExpressionSyntax literalParent) + { + Process(literalParent); + continue; + } + if (parent is NameColonSyntax) + parent = parent.Parent; + if (parent is null) + continue; + var child = (SyntaxNode?)parent.ChildThatContainsPosition(start); + if (child is null) + continue; + + // Now, check to see if it's a literal string + if (child is LiteralExpressionSyntax literalText) + Process(literalText); + else if (child is ArgumentSyntax argument && argument.Expression is LiteralExpressionSyntax literalArgText) + Process(literalArgText); + } + } + } + } + localized = [.. localizedStrings]; + return found; + } } } diff --git a/private/Nitrocid.LocaleClean/Analyzers/IAnalyzer.cs b/public/Nitrocid.Locales/Actions/Arguments/CheckerArgument.cs similarity index 75% rename from private/Nitrocid.LocaleClean/Analyzers/IAnalyzer.cs rename to public/Nitrocid.Locales/Actions/Arguments/CheckerArgument.cs index b44d0e7f6d..8e302beebe 100644 --- a/private/Nitrocid.LocaleClean/Analyzers/IAnalyzer.cs +++ b/public/Nitrocid.Locales/Actions/Arguments/CheckerArgument.cs @@ -17,12 +17,13 @@ // along with this program. If not, see . // -using Microsoft.CodeAnalysis; +using Terminaux.Shell.Arguments.Base; -namespace Nitrocid.LocaleClean.Analyzers +namespace Nitrocid.Locales.Actions.Arguments { - internal interface IAnalyzer + internal class CheckerArgument : ArgumentExecutor, IArgument { - bool Analyze(Document document, out string[] localized); + public override void Execute(ArgumentParameters parameters) => + Checker.Execute(); } } diff --git a/private/Nitrocid.LocaleCheckerStandalone/AnalyzersList.cs b/public/Nitrocid.Locales/Actions/Arguments/CleanerArgument.cs similarity index 59% rename from private/Nitrocid.LocaleCheckerStandalone/AnalyzersList.cs rename to public/Nitrocid.Locales/Actions/Arguments/CleanerArgument.cs index 834f4245d1..db3b1e177e 100644 --- a/private/Nitrocid.LocaleCheckerStandalone/AnalyzersList.cs +++ b/public/Nitrocid.Locales/Actions/Arguments/CleanerArgument.cs @@ -17,18 +17,17 @@ // along with this program. If not, see . // -using Nitrocid.LocaleCheckerStandalone.Analyzers; +using Terminaux.Shell.Arguments.Base; +using Terminaux.Shell.Switches; -namespace Nitrocid.LocaleCheckerStandalone +namespace Nitrocid.Locales.Actions.Arguments { - internal static class AnalyzersList + internal class CleanerArgument : ArgumentExecutor, IArgument { - // For contributors: If you're going to add a new analyzer, you need to copy the implementation from Analyzers to here, - // and make a dedicated diagnostic class for the standalone analyzer to recognize your new analyzer. - internal static readonly IAnalyzer[] analyzers = - [ - new NLOC0001(), - new NLOC0001Implicit(), - ]; + public override void Execute(ArgumentParameters parameters) + { + bool dry = SwitchManager.ContainsSwitch(parameters.SwitchesList, "-dry"); + Cleaner.Execute(dry); + } } } diff --git a/public/Nitrocid.Locales/Actions/Arguments/GeneratorArgument.cs b/public/Nitrocid.Locales/Actions/Arguments/GeneratorArgument.cs new file mode 100644 index 0000000000..c85bbe8d30 --- /dev/null +++ b/public/Nitrocid.Locales/Actions/Arguments/GeneratorArgument.cs @@ -0,0 +1,40 @@ +// +// Nitrocid KS Copyright (C) 2018-2025 Aptivi +// +// This file is part of Nitrocid KS +// +// Nitrocid KS is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nitrocid KS is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using Terminaux.Shell.Arguments.Base; +using Terminaux.Shell.Switches; + +namespace Nitrocid.Locales.Actions.Arguments +{ + internal class GeneratorArgument : ArgumentExecutor, IArgument + { + public override void Execute(ArgumentParameters parameters) + { + bool dry = SwitchManager.ContainsSwitch(parameters.SwitchesList, "-dry"); + bool all = SwitchManager.ContainsSwitch(parameters.SwitchesList, "-all") || true; + bool custom = SwitchManager.ContainsSwitch(parameters.SwitchesList, "-custom") || all; + bool addon = SwitchManager.ContainsSwitch(parameters.SwitchesList, "-addon") || all; + bool normal = SwitchManager.ContainsSwitch(parameters.SwitchesList, "-normal") || all; + bool resources = SwitchManager.ContainsSwitch(parameters.SwitchesList, "-resources"); + bool singular = SwitchManager.ContainsSwitch(parameters.SwitchesList, "-singular"); + string toSearch = SwitchManager.GetSwitchValue(parameters.SwitchesList, "-singular"); + Generator.Execute(custom, addon, normal, dry, resources, toSearch); + } + } +} diff --git a/public/Nitrocid.Locales/Actions/Arguments/HelpArgument.cs b/public/Nitrocid.Locales/Actions/Arguments/HelpArgument.cs new file mode 100644 index 0000000000..59f0f1aa95 --- /dev/null +++ b/public/Nitrocid.Locales/Actions/Arguments/HelpArgument.cs @@ -0,0 +1,37 @@ +// +// Nitrocid KS Copyright (C) 2018-2025 Aptivi +// +// This file is part of Nitrocid KS +// +// Nitrocid KS is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nitrocid KS is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Linq; +using Terminaux.Shell.Arguments.Base; +using Terminaux.Shell.Arguments.Base.Help; + +namespace Nitrocid.Locales.Actions.Arguments +{ + internal class HelpArgument : ArgumentExecutor, IArgument + { + public override void Execute(ArgumentParameters parameters) + { + var arguments = EntryPoint.argumentsMain.ToDictionary((ai) => ai.Argument, (ai) => ai); + if (parameters.ArgumentsList.Length > 0) + ArgumentHelpPrint.ShowArgsHelp(parameters.ArgumentsList[0], arguments); + else + ArgumentHelpPrint.ShowArgsHelp(arguments); + } + } +} diff --git a/public/Nitrocid.Locales/Actions/Arguments/TrimmerArgument.cs b/public/Nitrocid.Locales/Actions/Arguments/TrimmerArgument.cs new file mode 100644 index 0000000000..3a12b29c05 --- /dev/null +++ b/public/Nitrocid.Locales/Actions/Arguments/TrimmerArgument.cs @@ -0,0 +1,33 @@ +// +// Nitrocid KS Copyright (C) 2018-2025 Aptivi +// +// This file is part of Nitrocid KS +// +// Nitrocid KS is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nitrocid KS is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using Terminaux.Shell.Arguments.Base; +using Terminaux.Shell.Switches; + +namespace Nitrocid.Locales.Actions.Arguments +{ + internal class TrimmerArgument : ArgumentExecutor, IArgument + { + public override void Execute(ArgumentParameters parameters) + { + bool dry = SwitchManager.ContainsSwitch(parameters.SwitchesList, "-dry"); + Trimmer.Execute(dry); + } + } +} diff --git a/private/Nitrocid.LocaleCheckerStandalone/EntryPoint.cs b/public/Nitrocid.Locales/Actions/Checker.cs similarity index 72% rename from private/Nitrocid.LocaleCheckerStandalone/EntryPoint.cs rename to public/Nitrocid.Locales/Actions/Checker.cs index aea40bddeb..749eb7a4c6 100644 --- a/private/Nitrocid.LocaleCheckerStandalone/EntryPoint.cs +++ b/public/Nitrocid.Locales/Actions/Checker.cs @@ -22,7 +22,8 @@ using Microsoft.CodeAnalysis.MSBuild; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Nitrocid.LocaleCheckerStandalone.Analyzers; +using Nitrocid.Locales.Actions.Analyzers; +using Nitrocid.Locales.Serializer; using System; using System.Collections.Generic; using System.IO; @@ -32,16 +33,15 @@ using Terminaux.Colors.Data; using Terminaux.Reader; using Terminaux.Writer.ConsoleWriters; +using static Nitrocid.Locales.Serializer.VisualStudioInstanceSelector; -namespace Nitrocid.LocaleCheckerStandalone +namespace Nitrocid.Locales.Actions { - internal class EntryPoint + internal static class Checker { internal static readonly HashSet localizationList = []; - internal static readonly Assembly thisAssembly = - typeof(EntryPoint).Assembly; - static async Task Main() + internal static void Execute() { try { @@ -62,7 +62,7 @@ static async Task Main() }; // Check for Nitrocid solution - var solutionPath = "../../../../../Nitrocid.sln"; + var solutionPath = "../../../../Nitrocid.sln"; if (!File.Exists(solutionPath)) { TextWriterColor.WriteColor("Can't find Nitrocid solution. Make sure that it's run from the Nitrocid repo.", true, ConsoleColors.Red); @@ -71,11 +71,11 @@ static async Task Main() // Attach progress reporter so we print projects as they are loaded. TextWriterColor.Write($"Loading solution {solutionPath}..."); - var solution = await workspace.OpenSolutionAsync(solutionPath, new ConsoleProgressReporter()); + var solution = workspace.OpenSolutionAsync(solutionPath, new ConsoleProgressReporter()).Result; TextWriterColor.WriteColor($"Finished loading solution {solutionPath}!", true, ConsoleColors.Green); // Find the English JSON stream and open it. - var stream = thisAssembly.GetManifestResourceStream("Nitrocid.LocaleCheckerStandalone.eng.json") ?? + var stream = EntryPoint.thisAssembly.GetManifestResourceStream("Nitrocid.Locales.eng.json") ?? throw new Exception("Opening the eng.json resource stream has failed."); var reader = new StreamReader(stream); var jsonReader = new JsonTextReader(reader); @@ -101,7 +101,7 @@ static async Task Main() var documents = project.Documents; foreach (var document in documents) { - foreach (var analyzer in AnalyzersList.analyzers) + foreach (var analyzer in LocalizableResourcesAnalyzer.analyzers) { try { @@ -139,41 +139,5 @@ static async Task Main() TextWriterColor.WriteColor($"General analysis failure: {ex.Message}", true, ConsoleColors.Red); } } - - private static VisualStudioInstance SelectVisualStudioInstance(VisualStudioInstance[] visualStudioInstances) - { - TextWriterColor.Write("Select a Visual Studio instance:"); - for (int i = 0; i < visualStudioInstances.Length; i++) - { - TextWriterColor.Write($"Instance {i + 1}"); - TextWriterColor.Write($" - Name: {visualStudioInstances[i].Name}"); - TextWriterColor.Write($" - Version: {visualStudioInstances[i].Version}"); - TextWriterColor.Write($" - MSBuild Path: {visualStudioInstances[i].MSBuildPath}"); - } - - while (true) - { - var userResponse = TermReader.Read(">> "); - if (int.TryParse(userResponse, out int instanceNumber) && - instanceNumber > 0 && - instanceNumber <= visualStudioInstances.Length) - { - return visualStudioInstances[instanceNumber - 1]; - } - TextWriterColor.WriteColor("Input not accepted, try again.", true, ConsoleColors.Red); - } - } - - private class ConsoleProgressReporter : IProgress - { - public void Report(ProjectLoadProgress loadProgress) - { - var projectDisplay = Path.GetFileName(loadProgress.FilePath); - if (loadProgress.TargetFramework != null) - projectDisplay += $" ({loadProgress.TargetFramework})"; - - TextWriterColor.Write($"{loadProgress.Operation,-15} {loadProgress.ElapsedTime,-15:m\\:ss\\.fffffff} {projectDisplay}"); - } - } } } diff --git a/private/Nitrocid.LocaleClean/EntryPoint.cs b/public/Nitrocid.Locales/Actions/Cleaner.cs similarity index 66% rename from private/Nitrocid.LocaleClean/EntryPoint.cs rename to public/Nitrocid.Locales/Actions/Cleaner.cs index 2b5a7c3dab..8362608193 100644 --- a/private/Nitrocid.LocaleClean/EntryPoint.cs +++ b/public/Nitrocid.Locales/Actions/Cleaner.cs @@ -22,27 +22,24 @@ using Microsoft.CodeAnalysis.MSBuild; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Nitrocid.LocaleClean.Analyzers; -using Nitrocid.LocaleCommon; +using Nitrocid.Locales.Actions.Analyzers; +using Nitrocid.Locales.Serializer; using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Reflection; -using System.Threading.Tasks; using Terminaux.Colors.Data; using Terminaux.Reader; using Terminaux.Writer.ConsoleWriters; +using static Nitrocid.Locales.Serializer.VisualStudioInstanceSelector; -namespace Nitrocid.LocaleClean +namespace Nitrocid.Locales.Actions { - internal class EntryPoint + internal static class Cleaner { internal static readonly List localizationList = []; - internal static readonly Assembly thisAssembly = - typeof(EntryPoint).Assembly; - static async Task Main() + internal static void Execute(bool dry = false) { try { @@ -63,7 +60,7 @@ static async Task Main() }; // Check for Nitrocid solution - var solutionPath = "../../../../../Nitrocid.sln"; + var solutionPath = "../../../../Nitrocid.sln"; if (!File.Exists(solutionPath)) { TextWriterColor.WriteColor("Can't find Nitrocid solution. Make sure that it's run from the Nitrocid repo.", true, ConsoleColors.Red); @@ -72,11 +69,11 @@ static async Task Main() // Attach progress reporter so we print projects as they are loaded. TextWriterColor.Write($"Loading solution {solutionPath}..."); - var solution = await workspace.OpenSolutionAsync(solutionPath, new ConsoleProgressReporter()); + var solution = workspace.OpenSolutionAsync(solutionPath, new ConsoleProgressReporter()).Result; TextWriterColor.WriteColor($"Finished loading solution {solutionPath}!", true, ConsoleColors.Green); // Find the English JSON stream and open it. - var stream = thisAssembly.GetManifestResourceStream("Nitrocid.LocaleClean.eng.json") ?? + var stream = EntryPoint.thisAssembly.GetManifestResourceStream("Nitrocid.Locales.eng.json") ?? throw new Exception("Opening the eng.json resource stream has failed."); var reader = new StreamReader(stream); var jsonReader = new JsonTextReader(reader); @@ -102,11 +99,11 @@ static async Task Main() var documents = project.Documents; foreach (var document in documents) { - foreach (var analyzer in AnalyzersList.analyzers) + foreach (var analyzer in LocalizableResourcesAnalyzer.analyzers) { try { - if (analyzer.Analyze(document, out string[] localized)) + if (analyzer.ReverseAnalyze(document, out string[] localized)) { foreach (string localizedString in localized) { @@ -142,62 +139,31 @@ static async Task Main() indexes.Add(i); } } - var langs = LocalizationLister.PopulateLanguages(); - foreach (string localizationFile in langs.Keys) + + // If not dry, go ahead + if (!dry) { - // Delete all line numbers listed - for (int i = indexes.Count; i > 0; i--) + var langs = LocalizationLister.PopulateLanguages(); + foreach (string localizationFile in langs.Keys) { - int redundantIndex = indexes[i - 1]; - langs[localizationFile].RemoveAt(redundantIndex); - } + // Delete all line numbers listed + for (int i = indexes.Count; i > 0; i--) + { + int redundantIndex = indexes[i - 1]; + langs[localizationFile].RemoveAt(redundantIndex); + } - // Save the modified list to the file - TextWriterColor.WriteColor($"Sanitized: {localizationFile}", true, ConsoleColors.Lime); - File.WriteAllLines(localizationFile, langs[localizationFile]); + // Save the modified list to the file + TextWriterColor.WriteColor($"Sanitized: {localizationFile}", true, ConsoleColors.Lime); + File.WriteAllLines(localizationFile, langs[localizationFile]); + } + TextWriterColor.Write("Done! Please use the generation section to finalize the change.", true, ConsoleColors.Lime); } - TextWriterColor.Write("Done! Please use Nitrocid.LocaleGen to finalize the change.", true, ConsoleColors.Lime); } catch (Exception ex) { TextWriterColor.WriteColor($"General analysis failure: {ex.Message}", true, ConsoleColors.Red); } } - - private static VisualStudioInstance SelectVisualStudioInstance(VisualStudioInstance[] visualStudioInstances) - { - TextWriterColor.Write("Select a Visual Studio instance:"); - for (int i = 0; i < visualStudioInstances.Length; i++) - { - TextWriterColor.Write($"Instance {i + 1}"); - TextWriterColor.Write($" - Name: {visualStudioInstances[i].Name}"); - TextWriterColor.Write($" - Version: {visualStudioInstances[i].Version}"); - TextWriterColor.Write($" - MSBuild Path: {visualStudioInstances[i].MSBuildPath}"); - } - - while (true) - { - var userResponse = TermReader.Read(">> "); - if (int.TryParse(userResponse, out int instanceNumber) && - instanceNumber > 0 && - instanceNumber <= visualStudioInstances.Length) - { - return visualStudioInstances[instanceNumber - 1]; - } - TextWriterColor.WriteColor("Input not accepted, try again.", true, ConsoleColors.Red); - } - } - - private class ConsoleProgressReporter : IProgress - { - public void Report(ProjectLoadProgress loadProgress) - { - var projectDisplay = Path.GetFileName(loadProgress.FilePath); - if (loadProgress.TargetFramework != null) - projectDisplay += $" ({loadProgress.TargetFramework})"; - - TextWriterColor.Write($"{loadProgress.Operation,-15} {loadProgress.ElapsedTime,-15:m\\:ss\\.fffffff} {projectDisplay}"); - } - } } } diff --git a/public/Nitrocid.Locales/Actions/Generator.cs b/public/Nitrocid.Locales/Actions/Generator.cs new file mode 100644 index 0000000000..9c3b87edf1 --- /dev/null +++ b/public/Nitrocid.Locales/Actions/Generator.cs @@ -0,0 +1,60 @@ +// +// Nitrocid KS Copyright (C) 2018-2025 Aptivi +// +// This file is part of Nitrocid KS +// +// Nitrocid KS is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nitrocid KS is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System; +using System.Collections.Generic; +using System.IO; +using Terminaux.Writer.ConsoleWriters; +using Terminaux.Base.Checks; +using Nitrocid.Locales.Serializer; +using Terminaux.Colors.Data; + +namespace Nitrocid.Locales.Actions +{ + internal static class Generator + { + internal static void Execute(bool custom = true, bool addon = true, bool normal = true, bool dry = false, bool copyToResources = false, string toSearch = "") + { + try + { + // Get the translation folders + string translations = Path.GetFullPath("Translations"); + string translationsAddon = Path.GetFullPath("AddonTranslations"); + string customs = Path.GetFullPath("CustomLanguages"); + + // Warn if dry + if (dry) + TextWriterColor.WriteColor("Running in dry mode. No changes will be made. Take out the -dry switch if you really want to apply changes. Look at the debug window.", ConsoleColors.Yellow); + + // Now, do the job! + if (normal) + LanguageGenerator.GenerateLocaleFiles(translations, toSearch, copyToResources, dry); + if (addon) + LanguageGenerator.GenerateLocaleFiles(translationsAddon, toSearch, copyToResources, dry); + if (custom) + LanguageGenerator.GenerateLocaleFiles(customs, toSearch, copyToResources, dry); + } + catch (Exception ex) + { + TextWriterColor.WriteColor("Unexpected error in converter:" + $" {ex.Message}", ConsoleColors.Red); + TextWriterColor.WriteColor(ex.StackTrace ?? "No stack trace!", ConsoleColors.Red); + } + } + } +} diff --git a/private/Nitrocid.LocaleTrim/Trimmer.cs b/public/Nitrocid.Locales/Actions/Trimmer.cs similarity index 85% rename from private/Nitrocid.LocaleTrim/Trimmer.cs rename to public/Nitrocid.Locales/Actions/Trimmer.cs index f163555815..be20696ac7 100644 --- a/private/Nitrocid.LocaleTrim/Trimmer.cs +++ b/public/Nitrocid.Locales/Actions/Trimmer.cs @@ -17,7 +17,7 @@ // along with this program. If not, see . // -using Nitrocid.LocaleCommon; +using Nitrocid.Locales.Serializer; using System.Collections.Generic; using System.IO; using System.Linq; @@ -25,18 +25,15 @@ using Terminaux.Writer.ConsoleWriters; using Terminaux.Writer.CyclicWriters; -namespace Nitrocid.LocaleTrim +namespace Nitrocid.Locales.Actions { - internal class Trimmer + internal static class Trimmer { - static int Main(string[] args) + internal static void Execute(bool dry = false) { - // If on dry mode, set as appropriate - bool dry = args.Contains("-dry"); - // Check to see if we're running on the KS repo - string metadataFile = "../../../../../public/Nitrocid.LocaleGen/Translations/Metadata.json"; - string addonMetadataFile = "../../../../../public/Nitrocid.LocaleGen/AddonTranslations/Metadata.json"; + string metadataFile = "../../../Nitrocid.Locales/Translations/Metadata.json"; + string addonMetadataFile = "../../../Nitrocid.Locales/AddonTranslations/Metadata.json"; if (File.Exists(metadataFile) && File.Exists(addonMetadataFile)) { // Iterate through all the language files for the main project @@ -71,7 +68,7 @@ static int Main(string[] args) KeyColor = ConsoleColors.Yellow, ValueColor = ConsoleColors.Red, }; - TextWriterRaw.WriteRaw(listing.Render()); + TextWriterRaw.WritePlain(listing.Render()); } else { @@ -86,13 +83,9 @@ static int Main(string[] args) TextWriterColor.Write($"There are no redundant languages! Congratulations!"); else TextWriterColor.Write($"Removed all redundant languages! Please verify that only the redundant ones have been removed. You may need to remove their associated JSON files and their metadata."); - return 0; } else - { TextWriterColor.Write("This internal program needs to be run within the Nitrocid KS repository.", true, ConsoleColors.Red); - return 1; - } } } } diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/Metadata.json b/public/Nitrocid.Locales/AddonTranslations/Metadata.json similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/Metadata.json rename to public/Nitrocid.Locales/AddonTranslations/Metadata.json diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/arb-T.txt b/public/Nitrocid.Locales/AddonTranslations/arb-T.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/arb-T.txt rename to public/Nitrocid.Locales/AddonTranslations/arb-T.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/arb.txt b/public/Nitrocid.Locales/AddonTranslations/arb.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/arb.txt rename to public/Nitrocid.Locales/AddonTranslations/arb.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/brz.txt b/public/Nitrocid.Locales/AddonTranslations/brz.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/brz.txt rename to public/Nitrocid.Locales/AddonTranslations/brz.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/chi-T.txt b/public/Nitrocid.Locales/AddonTranslations/chi-T.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/chi-T.txt rename to public/Nitrocid.Locales/AddonTranslations/chi-T.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/chi.txt b/public/Nitrocid.Locales/AddonTranslations/chi.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/chi.txt rename to public/Nitrocid.Locales/AddonTranslations/chi.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/cnt-T.txt b/public/Nitrocid.Locales/AddonTranslations/cnt-T.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/cnt-T.txt rename to public/Nitrocid.Locales/AddonTranslations/cnt-T.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/cnt.txt b/public/Nitrocid.Locales/AddonTranslations/cnt.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/cnt.txt rename to public/Nitrocid.Locales/AddonTranslations/cnt.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/dtc.txt b/public/Nitrocid.Locales/AddonTranslations/dtc.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/dtc.txt rename to public/Nitrocid.Locales/AddonTranslations/dtc.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/eng.txt b/public/Nitrocid.Locales/AddonTranslations/eng.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/eng.txt rename to public/Nitrocid.Locales/AddonTranslations/eng.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/enk.txt b/public/Nitrocid.Locales/AddonTranslations/enk.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/enk.txt rename to public/Nitrocid.Locales/AddonTranslations/enk.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/fre.txt b/public/Nitrocid.Locales/AddonTranslations/fre.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/fre.txt rename to public/Nitrocid.Locales/AddonTranslations/fre.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/ger.txt b/public/Nitrocid.Locales/AddonTranslations/ger.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/ger.txt rename to public/Nitrocid.Locales/AddonTranslations/ger.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/grk.txt b/public/Nitrocid.Locales/AddonTranslations/grk.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/grk.txt rename to public/Nitrocid.Locales/AddonTranslations/grk.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/ind-T.txt b/public/Nitrocid.Locales/AddonTranslations/ind-T.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/ind-T.txt rename to public/Nitrocid.Locales/AddonTranslations/ind-T.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/ind.txt b/public/Nitrocid.Locales/AddonTranslations/ind.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/ind.txt rename to public/Nitrocid.Locales/AddonTranslations/ind.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/iri.txt b/public/Nitrocid.Locales/AddonTranslations/iri.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/iri.txt rename to public/Nitrocid.Locales/AddonTranslations/iri.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/ita.txt b/public/Nitrocid.Locales/AddonTranslations/ita.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/ita.txt rename to public/Nitrocid.Locales/AddonTranslations/ita.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/jpn.txt b/public/Nitrocid.Locales/AddonTranslations/jpn.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/jpn.txt rename to public/Nitrocid.Locales/AddonTranslations/jpn.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/kor-T.txt b/public/Nitrocid.Locales/AddonTranslations/kor-T.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/kor-T.txt rename to public/Nitrocid.Locales/AddonTranslations/kor-T.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/kor.txt b/public/Nitrocid.Locales/AddonTranslations/kor.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/kor.txt rename to public/Nitrocid.Locales/AddonTranslations/kor.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/ltn.txt b/public/Nitrocid.Locales/AddonTranslations/ltn.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/ltn.txt rename to public/Nitrocid.Locales/AddonTranslations/ltn.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/mal.txt b/public/Nitrocid.Locales/AddonTranslations/mal.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/mal.txt rename to public/Nitrocid.Locales/AddonTranslations/mal.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/nor.txt b/public/Nitrocid.Locales/AddonTranslations/nor.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/nor.txt rename to public/Nitrocid.Locales/AddonTranslations/nor.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/ptg.txt b/public/Nitrocid.Locales/AddonTranslations/ptg.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/ptg.txt rename to public/Nitrocid.Locales/AddonTranslations/ptg.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/rmn.txt b/public/Nitrocid.Locales/AddonTranslations/rmn.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/rmn.txt rename to public/Nitrocid.Locales/AddonTranslations/rmn.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/spa.txt b/public/Nitrocid.Locales/AddonTranslations/spa.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/spa.txt rename to public/Nitrocid.Locales/AddonTranslations/spa.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/tky.txt b/public/Nitrocid.Locales/AddonTranslations/tky.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/tky.txt rename to public/Nitrocid.Locales/AddonTranslations/tky.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/ukr.txt b/public/Nitrocid.Locales/AddonTranslations/ukr.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/ukr.txt rename to public/Nitrocid.Locales/AddonTranslations/ukr.txt diff --git a/public/Nitrocid.LocaleGen/AddonTranslations/vtn.txt b/public/Nitrocid.Locales/AddonTranslations/vtn.txt similarity index 100% rename from public/Nitrocid.LocaleGen/AddonTranslations/vtn.txt rename to public/Nitrocid.Locales/AddonTranslations/vtn.txt diff --git a/public/Nitrocid.LocaleGen/CustomLanguages/Metadata.json b/public/Nitrocid.Locales/CustomLanguages/Metadata.json similarity index 100% rename from public/Nitrocid.LocaleGen/CustomLanguages/Metadata.json rename to public/Nitrocid.Locales/CustomLanguages/Metadata.json diff --git a/public/Nitrocid.LocaleGen/CustomLanguages/eng.txt b/public/Nitrocid.Locales/CustomLanguages/eng.txt similarity index 100% rename from public/Nitrocid.LocaleGen/CustomLanguages/eng.txt rename to public/Nitrocid.Locales/CustomLanguages/eng.txt diff --git a/public/Nitrocid.Locales/EntryPoint.cs b/public/Nitrocid.Locales/EntryPoint.cs new file mode 100644 index 0000000000..b71cebce48 --- /dev/null +++ b/public/Nitrocid.Locales/EntryPoint.cs @@ -0,0 +1,112 @@ +// +// Nitrocid KS Copyright (C) 2018-2025 Aptivi +// +// This file is part of Nitrocid KS +// +// Nitrocid KS is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nitrocid KS is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using Nitrocid.Locales.Actions.Arguments; +using System.Linq; +using System.Reflection; +using Terminaux.Base.Checks; +using Terminaux.Shell.Arguments; +using Terminaux.Shell.Arguments.Base; +using Terminaux.Shell.Switches; + +namespace Nitrocid.Locales +{ + internal static class EntryPoint + { + internal static readonly ArgumentInfo[] argumentsMain = + [ + new("check", "Checks the localizations", + [ + new CommandArgumentInfo() + ], new CheckerArgument()), + + new("clean", "Cleans unused localizations", + [ + new CommandArgumentInfo([ + new SwitchInfo("dry", "Performs this operation dryly", new() + { + AcceptsValues = false, + }), + ]) + ], new CleanerArgument()), + + new("generate", "Generates localization info and metadata", + [ + new CommandArgumentInfo([ + new SwitchInfo("dry", "Performs this operation dryly", new() + { + AcceptsValues = false, + }), + new SwitchInfo("custom", "Generates localization info from custom language files", new() + { + AcceptsValues = false, + }), + new SwitchInfo("addon", "Generates localization info from language files found in the addon translations folder", new() + { + AcceptsValues = false, + }), + new SwitchInfo("normal", "Generates localization info from language files found in the base translations folder", new() + { + AcceptsValues = false, + }), + new SwitchInfo("all", "Generates localization info from all language files", new() + { + AcceptsValues = false, + }), + new SwitchInfo("resources", "Copies the generated files to the resources", new() + { + AcceptsValues = false, + }), + new SwitchInfo("singular", "Allows you to generate a single language", new()), + ]) + ], new GeneratorArgument()), + + new("trim", "Trims redundant languages", + [ + new CommandArgumentInfo([ + new SwitchInfo("dry", "Performs this operation dryly", new() + { + AcceptsValues = false, + }), + ]) + ], new TrimmerArgument()), + + new("help", "Shows this help page", + [ + new CommandArgumentInfo([ + new CommandArgumentPart(false, "argument", new()), + ]) + ], new HelpArgument()), + ]; + internal static readonly Assembly thisAssembly = typeof(EntryPoint).Assembly; + + /// + /// Entry point + /// + public static void Main(string[] args) + { + // Check console + ConsoleChecker.CheckConsole(); + + // Check the arguments + var arguments = argumentsMain.ToDictionary((ai) => ai.Argument, (ai) => ai); + ArgumentParse.ParseArguments([string.Join(" ", args)], arguments); + } + } +} diff --git a/public/Nitrocid.Locales/Nitrocid.Locales.csproj b/public/Nitrocid.Locales/Nitrocid.Locales.csproj new file mode 100644 index 0000000000..c67e8b7c23 --- /dev/null +++ b/public/Nitrocid.Locales/Nitrocid.Locales.csproj @@ -0,0 +1,97 @@ + + + + Debug + AnyCPU + Exe + AnyCPU + true + true + Nitrocid.Locales + ..\Nitrocid\KSBuild\ + Nitrocid KS - Locale Tools + Nitrocid KS - Locale Tools + ../Nitrocid/OfficialAppIcon-NitrocidKS.ico + + + + + + true + + + false + true + + + + + + + + + + + + + Always + + + Always + + + Always + + + Always + + + + + + + + + Always + + + Always + + + + + + + + + + + + + + + + + + + + + %(EmbeddedResource.FullPath) + + + %(EmbeddedResource.FullPath) + + + %(EmbeddedResource.FullPath) + + + %(EmbeddedResource.FullPath) + + + %(EmbeddedResource.FullPath) + + + + + + diff --git a/public/Nitrocid.Locales/Properties/launchSettings.json b/public/Nitrocid.Locales/Properties/launchSettings.json new file mode 100644 index 0000000000..3df71df290 --- /dev/null +++ b/public/Nitrocid.Locales/Properties/launchSettings.json @@ -0,0 +1,56 @@ +{ + "profiles": { + "Nitrocid.Locales - Generate": { + "commandName": "Project", + "commandLineArgs": "generate" + }, + "Nitrocid.Locales - Generate - Dry": { + "commandName": "Project", + "commandLineArgs": "generate -dry -all" + }, + "Nitrocid.Locales - Generate - Copy localizations to resources": { + "commandName": "Project", + "commandLineArgs": "generate -resources -all" + }, + "Nitrocid.Locales - Generate - Dry & Copy to resources": { + "commandName": "Project", + "commandLineArgs": "generate -dry -resources -all" + }, + "Nitrocid.Locales - Generate - Dry & Custom Only": { + "commandName": "Project", + "commandLineArgs": "generate -dry -custom" + }, + "Nitrocid.Locales - Generate - Dry & Normal Only": { + "commandName": "Project", + "commandLineArgs": "generate -dry -normal" + }, + "Nitrocid.Locales - Generate - Dry & Addon Only": { + "commandName": "Project", + "commandLineArgs": "generate -dry -addon" + }, + "Nitrocid.Locales - Trim": { + "commandName": "Project", + "commandLineArgs": "trim" + }, + "Nitrocid.Locales - Trim - Dry": { + "commandName": "Project", + "commandLineArgs": "trim -dry" + }, + "Nitrocid.Locales - Clean": { + "commandName": "Project", + "commandLineArgs": "clean" + }, + "Nitrocid.Locales - Clean - Dry": { + "commandName": "Project", + "commandLineArgs": "clean -dry" + }, + "Nitrocid.Locales - Check": { + "commandName": "Project", + "commandLineArgs": "check" + }, + "Nitrocid.Locales - Help": { + "commandName": "Project", + "commandLineArgs": "help" + } + } +} diff --git a/public/Nitrocid.LocaleGen/Serializer/LanguageGenerator.cs b/public/Nitrocid.Locales/Serializer/LanguageGenerator.cs similarity index 98% rename from public/Nitrocid.LocaleGen/Serializer/LanguageGenerator.cs rename to public/Nitrocid.Locales/Serializer/LanguageGenerator.cs index 451fda705f..d22f12ff60 100644 --- a/public/Nitrocid.LocaleGen/Serializer/LanguageGenerator.cs +++ b/public/Nitrocid.Locales/Serializer/LanguageGenerator.cs @@ -20,7 +20,7 @@ using System; using System.Collections.Generic; -namespace Nitrocid.LocaleGen.Core.Serializer +namespace Nitrocid.Locales.Serializer { internal static class LanguageGenerator { diff --git a/private/Nitrocid.LocaleCommon/LanguageMetadata.cs b/public/Nitrocid.Locales/Serializer/LanguageMetadata.cs similarity index 98% rename from private/Nitrocid.LocaleCommon/LanguageMetadata.cs rename to public/Nitrocid.Locales/Serializer/LanguageMetadata.cs index dec2f6fb33..e2c1d903c3 100644 --- a/private/Nitrocid.LocaleCommon/LanguageMetadata.cs +++ b/public/Nitrocid.Locales/Serializer/LanguageMetadata.cs @@ -19,7 +19,7 @@ using Newtonsoft.Json; -namespace Nitrocid.LocaleCommon +namespace Nitrocid.Locales.Serializer { internal class LanguageMetadata { diff --git a/private/Nitrocid.LocaleCommon/LocalizationLister.cs b/public/Nitrocid.Locales/Serializer/LocalizationLister.cs similarity index 85% rename from private/Nitrocid.LocaleCommon/LocalizationLister.cs rename to public/Nitrocid.Locales/Serializer/LocalizationLister.cs index 5ca711ea0c..681b0e7666 100644 --- a/private/Nitrocid.LocaleCommon/LocalizationLister.cs +++ b/public/Nitrocid.Locales/Serializer/LocalizationLister.cs @@ -23,15 +23,15 @@ using System.IO; using System.Linq; -namespace Nitrocid.LocaleCommon +namespace Nitrocid.Locales.Serializer { internal static class LocalizationLister { private static string[] ListLanguageFilesForKS() { // Check to see if we have the Nitrocid KS folder - string ksJsonifyLocalesSource = "../../../../../public/Nitrocid.LocaleGen/Translations"; - string ksJsonifyLocalesAddonSource = "../../../../../public/Nitrocid.LocaleGen/AddonTranslations"; + string ksJsonifyLocalesSource = "../../../Nitrocid.Locales/Translations"; + string ksJsonifyLocalesAddonSource = "../../../Nitrocid.Locales/AddonTranslations"; List translations = []; if (Directory.Exists(ksJsonifyLocalesSource)) { @@ -61,8 +61,8 @@ internal static Dictionary> PopulateLanguages() internal static LanguageMetadata[] PopulateLanguageMetadata() { - string metadataFile = "../../../../../public/Nitrocid.LocaleGen/Translations/Metadata.json"; - string addonMetadataFile = "../../../../../public/Nitrocid.LocaleGen/AddonTranslations/Metadata.json"; + string metadataFile = "../../../Nitrocid.Locales/Translations/Metadata.json"; + string addonMetadataFile = "../../../Nitrocid.Locales/AddonTranslations/Metadata.json"; string metadata = File.ReadAllText(metadataFile); string addonMetadata = File.ReadAllText(addonMetadataFile); var languageMetadataToken = JsonConvert.DeserializeObject(metadata) ?? diff --git a/public/Nitrocid.LocaleGen/Serializer/SerializerTools.cs b/public/Nitrocid.Locales/Serializer/SerializerTools.cs similarity index 99% rename from public/Nitrocid.LocaleGen/Serializer/SerializerTools.cs rename to public/Nitrocid.Locales/Serializer/SerializerTools.cs index a605c4d762..585f0b1e3a 100644 --- a/public/Nitrocid.LocaleGen/Serializer/SerializerTools.cs +++ b/public/Nitrocid.Locales/Serializer/SerializerTools.cs @@ -25,7 +25,7 @@ using System.IO; using System.Linq; -namespace Nitrocid.LocaleGen.Core.Serializer +namespace Nitrocid.Locales.Serializer { internal static class SerializerTools { diff --git a/public/Nitrocid.LocaleGen/Serializer/TargetLanguage.cs b/public/Nitrocid.Locales/Serializer/TargetLanguage.cs similarity index 97% rename from public/Nitrocid.LocaleGen/Serializer/TargetLanguage.cs rename to public/Nitrocid.Locales/Serializer/TargetLanguage.cs index c3b97ddeb1..c7ba162b58 100644 --- a/public/Nitrocid.LocaleGen/Serializer/TargetLanguage.cs +++ b/public/Nitrocid.Locales/Serializer/TargetLanguage.cs @@ -17,7 +17,7 @@ // along with this program. If not, see . // -namespace Nitrocid.LocaleGen.Core.Serializer +namespace Nitrocid.Locales.Serializer { /// /// Target language class diff --git a/public/Nitrocid.Locales/Serializer/VisualStudioInstanceSelector.cs b/public/Nitrocid.Locales/Serializer/VisualStudioInstanceSelector.cs new file mode 100644 index 0000000000..7e7893024b --- /dev/null +++ b/public/Nitrocid.Locales/Serializer/VisualStudioInstanceSelector.cs @@ -0,0 +1,72 @@ +// +// Nitrocid KS Copyright (C) 2018-2025 Aptivi +// +// This file is part of Nitrocid KS +// +// Nitrocid KS is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nitrocid KS is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using Microsoft.Build.Locator; +using Microsoft.CodeAnalysis.MSBuild; +using System; +using System.IO; +using Terminaux.Colors.Data; +using Terminaux.Reader; +using Terminaux.Writer.ConsoleWriters; + +namespace Nitrocid.Locales.Serializer +{ + internal static class VisualStudioInstanceSelector + { + internal static VisualStudioInstance SelectVisualStudioInstance(VisualStudioInstance[] visualStudioInstances) + { + // Check to see if the user has installed .NET SDK + if (visualStudioInstances.Length == 0) + throw new Exception("You should install a .NET SDK compatible with Nitrocid KS to continue."); + + TextWriterColor.Write("Select a Visual Studio instance:"); + for (int i = 0; i < visualStudioInstances.Length; i++) + { + TextWriterColor.Write($"Instance {i + 1}"); + TextWriterColor.Write($" - Name: {visualStudioInstances[i].Name}"); + TextWriterColor.Write($" - Version: {visualStudioInstances[i].Version}"); + TextWriterColor.Write($" - MSBuild Path: {visualStudioInstances[i].MSBuildPath}"); + } + + while (true) + { + var userResponse = TermReader.Read(">> "); + if (int.TryParse(userResponse, out int instanceNumber) && + instanceNumber > 0 && + instanceNumber <= visualStudioInstances.Length) + { + return visualStudioInstances[instanceNumber - 1]; + } + TextWriterColor.WriteColor("Input not accepted, try again.", true, ConsoleColors.Red); + } + } + + internal class ConsoleProgressReporter : IProgress + { + public void Report(ProjectLoadProgress loadProgress) + { + var projectDisplay = Path.GetFileName(loadProgress.FilePath); + if (loadProgress.TargetFramework != null) + projectDisplay += $" ({loadProgress.TargetFramework})"; + + TextWriterColor.Write($"{loadProgress.Operation,-15} {loadProgress.ElapsedTime,-15:m\\:ss\\.fffffff} {projectDisplay}"); + } + } + } +} diff --git a/public/Nitrocid.LocaleGen/Translations/Metadata.json b/public/Nitrocid.Locales/Translations/Metadata.json similarity index 100% rename from public/Nitrocid.LocaleGen/Translations/Metadata.json rename to public/Nitrocid.Locales/Translations/Metadata.json diff --git a/public/Nitrocid.LocaleGen/Translations/eng.txt b/public/Nitrocid.Locales/Translations/eng.txt similarity index 100% rename from public/Nitrocid.LocaleGen/Translations/eng.txt rename to public/Nitrocid.Locales/Translations/eng.txt