-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp - Now, LocaleClean actually cleans
--- Finally, Nitrocid.LocaleClean serves its own purpose by cleaning up locale files. --- Type: imp Breaking: False Doc Required: False Backport Required: False Part: 1/1
- Loading branch information
Showing
54 changed files
with
168 additions
and
1,640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// Nitrocid KS Copyright (C) 2018-2024 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 <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
using Newtonsoft.Json; | ||
|
||
namespace Nitrocid.LocaleClean | ||
{ | ||
internal class LanguageMetadata | ||
{ | ||
[JsonProperty(nameof(three))] | ||
private readonly string three; | ||
[JsonProperty(nameof(name))] | ||
private readonly string name; | ||
[JsonProperty(nameof(transliterable))] | ||
private readonly bool transliterable; | ||
[JsonProperty(nameof(codepage))] | ||
private readonly int codepage; | ||
[JsonProperty(nameof(culture))] | ||
private readonly string culture; | ||
[JsonProperty(nameof(country))] | ||
private readonly string country; | ||
|
||
[JsonIgnore] | ||
public string ThreeLetterLanguageName => | ||
three; | ||
[JsonIgnore] | ||
public string Name => | ||
name; | ||
[JsonIgnore] | ||
public bool Transliterable => | ||
transliterable; | ||
[JsonIgnore] | ||
public int Codepage => | ||
codepage; | ||
[JsonIgnore] | ||
public string Culture => | ||
culture; | ||
[JsonIgnore] | ||
public string Country => | ||
country; | ||
|
||
[JsonConstructor] | ||
internal LanguageMetadata(string three, string name, bool transliterable, int codepage, string culture, string country) | ||
{ | ||
this.three = three; | ||
this.name = name; | ||
this.transliterable = transliterable; | ||
this.codepage = codepage; | ||
this.culture = culture; | ||
this.country = country; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// Nitrocid KS Copyright (C) 2018-2024 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 <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Nitrocid.LocaleClean | ||
{ | ||
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"; | ||
List<string> translations = []; | ||
if (Directory.Exists(ksJsonifyLocalesSource)) | ||
{ | ||
// Iterate through all the source files for Nitrocid KS | ||
string[] files = Directory.GetFiles(ksJsonifyLocalesSource, "*.txt"); | ||
translations.AddRange(files); | ||
} | ||
if (Directory.Exists(ksJsonifyLocalesAddonSource)) | ||
{ | ||
// Iterate through all the source files for Nitrocid KS addons | ||
string[] files = Directory.GetFiles(ksJsonifyLocalesAddonSource, "*.txt"); | ||
translations.AddRange(files); | ||
} | ||
return [.. translations]; | ||
} | ||
|
||
internal static Dictionary<string, List<string>> PopulateLanguages() | ||
{ | ||
Dictionary<string, List<string>> sources = []; | ||
|
||
// List all code files to add the sources | ||
foreach (string source in ListLanguageFilesForKS()) | ||
sources.Add(source, [.. File.ReadAllLines(source)]); | ||
|
||
return sources; | ||
} | ||
|
||
internal static LanguageMetadata[] PopulateLanguageMetadata() | ||
{ | ||
string metadataFile = "../../../../../public/Nitrocid.LocaleGen/Translations/Metadata.json"; | ||
string addonMetadataFile = "../../../../../public/Nitrocid.LocaleGen/AddonTranslations/Metadata.json"; | ||
string metadata = File.ReadAllText(metadataFile); | ||
string addonMetadata = File.ReadAllText(addonMetadataFile); | ||
var languageMetadataToken = JsonConvert.DeserializeObject<LanguageMetadata[]>(metadata) ?? | ||
throw new Exception("Failed to get language metadata"); | ||
var languageAddonMetadataToken = JsonConvert.DeserializeObject<LanguageMetadata[]>(addonMetadata) ?? | ||
throw new Exception("Failed to get addon language metadata"); | ||
return languageMetadataToken.Union(languageAddonMetadataToken).ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.