Skip to content

Commit

Permalink
imp - Now, LocaleClean actually cleans
Browse files Browse the repository at this point in the history
---

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
AptiviCEO committed Sep 9, 2024
1 parent c2b0fb2 commit 87fc3ce
Show file tree
Hide file tree
Showing 54 changed files with 168 additions and 1,640 deletions.
24 changes: 20 additions & 4 deletions private/Nitrocid.LocaleClean/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Nitrocid.LocaleClean
{
internal class EntryPoint
{
internal static readonly HashSet<string> localizationList = [];
internal static readonly List<string> localizationList = [];
internal static readonly Assembly thisAssembly =
typeof(EntryPoint).Assembly;

Expand Down Expand Up @@ -131,15 +131,31 @@ static async Task Main()
}

// Remove all extra strings
List<string> extraStrings = [];
foreach (string maybeExtraString in localizationList)
List<int> indexes = [];
for (int i = 0; i < localizationList.Count; i++)
{
string maybeExtraString = localizationList[i];
if (!totalLocalized.Contains(maybeExtraString))
{
TextWriterColor.WriteColor($"Found extra string: {maybeExtraString}", true, ConsoleColors.Yellow);
extraStrings.Add(maybeExtraString);
indexes.Add(i);
}
}
var langs = LocalizationLister.PopulateLanguages();
foreach (string localizationFile in langs.Keys)
{
// 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]);
}
TextWriterColor.Write("Done! Please use Nitrocid.LocaleGen to finalize the change.", true, ConsoleColors.Lime);
}
catch (Exception ex)
{
Expand Down
69 changes: 69 additions & 0 deletions private/Nitrocid.LocaleClean/LanguageMetadata.cs
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;
}
}
}
75 changes: 75 additions & 0 deletions private/Nitrocid.LocaleClean/LocalizationLister.cs
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1770,37 +1770,8 @@
"هل يمكنك الحصول على نصائح إضافية من ملحق kernel الذي يتم شحنه مع الإصدار الكامل من Nitrocid؟",
"نصيحة للمحترفين: هل تعلم",
"روابط المفاتيح",
"إدراج",
"يزيل",
"يستبدل",
"استبدال الكل",
"استبدال كل ما",
"معلومات الرقم",
"فشل المحرر السداسي:",
"المفاتيح المتاحة",
"اكتب رقم البايت بالقيمة السداسية العشرية.",
"رقم البايت المحدد غير صالح.",
"اكتب رقم البايت بالقيمة السداسية العشرية لاستبدال {0} بها.",
"اكتب رقم البايت بالقيمة السداسية العشرية المراد استبدالها.",
"معلومات الرقم:",
"السداسي عشري",
"ثماني",
"رقم",
"الثنائية",
"لا يحتوي ربط المفاتيح هذا على أي إجراء.",
"لا يمكن تنفيذ هذه العملية على صفيف فارغ.",
"يدخل...",
"إزالة الخط",
"توقف عن الدخول",
"خط جديد",
"فشل محرر النصوص:",
"اكتب السلسلة للعثور عليها",
"اكتب سلسلة الاستبدال",
"خطوط",
"عمود",
"صف",
"سلة مهملات",
"فاتورة غير مدفوعة",
"لا يمكن إجراء هذه العملية على قائمة الأسطر الخالية.",
"لم يتم العثور على نوع الإعدادات.",
"ابحث عن خيار",
Expand All @@ -1827,7 +1798,6 @@
"حفظ الإعدادات إلى",
"جارٍ تحميل الإعدادات...",
"جارٍ إعادة تحميل الإعدادات...",
"تم تعطيل التحقق من وجود تحديثات في إصدارات التطوير.",
"إصدار النواة",
"إصدار واجهة برمجة تطبيقات النواة",
"معرف المضيف",
Expand Down Expand Up @@ -1996,7 +1966,6 @@
"أسلوب اختيار سطر واحد",
"أسلوب اختيار سطرين",
"أسلوب الاختيار الحديث",
"أسلوب اختيار الجدول",
"يمكن أن يكون الإخراج حرفًا واحدًا فقط",
"يمكن أن يكون الإخراج أكثر من حرف",
"يجمع الملفين النصيين أو أكثر في وحدة التحكم.",
Expand Down Expand Up @@ -3355,7 +3324,6 @@
"مرحبًا، {0}! مرحبا بكم في نيتروسيد!",
"تمكين العناوين عند تسجيل الدخول لإظهار خلاصات RSS",
"إعدادات",
"يغلق",
"Nitrocid KS يحاكي نواة المستقبل، Nitrocid Kernel.",
"وزارة الدفاع API",
"لقد تعطلت صفحة Nitrocid الرئيسية وتحتاج إلى العودة إلى الصدفة.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1770,37 +1770,8 @@
"hl īmknk al-ḥṣūl ʿli nṣāʾiḥ iḍāfīẗ mn mlḥq kernel al-ḏī ītm šḥnh mʿ al-iṣdār al-kāml mn Nitrocid?",
"nṣīḥẗ llmḥtrfīn: hl tʿlm",
"rwābṭ al-mfātīḥ",
"idrāǧ",
"īzīl",
"īstbdl",
"astbdāl al-kl",
"astbdāl kl mā",
"mʿlūmāt al-rqm",
"fšl al-mḥrr al-sdāsī:",
"al-mfātīḥ al-mtāḥẗ",
"aktb rqm al-bāīt bālqīmẗ al-sdāsīẗ al-ʿšrīẗ.",
"rqm al-bāīt al-mḥdd ġīr ṣālḥ.",
"aktb rqm al-bāīt bālqīmẗ al-sdāsīẗ al-ʿšrīẗ lāstbdāl {0} bhā.",
"aktb rqm al-bāīt bālqīmẗ al-sdāsīẗ al-ʿšrīẗ al-mrād astbdālhā.",
"mʿlūmāt al-rqm:",
"al-sdāsī ʿšrī",
"ṯmānī",
"rqm",
"al-ṯnāʾīẗ",
"lā īḥtwy rbṭ al-mfātīḥ hḏā ʿli aī iǧrāʾ.",
"lā īmkn tnfīḏ hḏh al-ʿmlīẗ ʿli ṣfīf fārġ.",
"īdẖl...",
"izālẗ al-ẖṭ",
"tūqf ʿn al-dẖūl",
"ẖṭ ǧdīd",
"fšl mḥrr al-nṣūṣ:",
"aktb al-slslẗ llʿṯūr ʿlīhā",
"aktb slslẗ al-āstbdāl",
"ẖṭūṭ",
"ʿmūd",
"ṣf",
"slẗ mhmlāt",
"fātūrẗ ġīr mdfūʿẗ",
"lā īmkn iǧrāʾ hḏh al-ʿmlīẗ ʿli qāʾimẗ al-ʾasṭr al-ẖālīẗ.",
"lm ītm al-ʿṯūr ʿli nūʿ al-iʿdādāt.",
"abḥṯ ʿn ẖīār",
Expand All @@ -1827,7 +1798,6 @@
"ḥfẓ al-iʿdādāt ili",
"ǧārٍ tḥmīl al-iʿdādāt...",
"ǧārٍ iʿādẗ tḥmīl al-iʿdādāt...",
"tm tʿṭīl al-tḥqq mn ūǧūd tḥdīṯāt fī iṣdārāt al-tṭwyr.",
"iṣdār al-nwāẗ",
"iṣdār wāǧhẗ brmǧẗ tṭbīqāt al-nwāẗ",
"mʿrf al-mḍīf",
Expand Down Expand Up @@ -1996,7 +1966,6 @@
"aslūb aẖtīār sṭr wāḥd",
"aslūb aẖtīār sṭrīn",
"aslūb al-āẖtīār al-ḥdīṯ",
"aslūb aẖtīār al-ǧdūl",
"īmkn an īkūn al-iẖrāǧ ḥrfًā wāḥddā fqṭ",
"īmkn an īkūn al-iẖrāǧ akṯr mn ḥrf",
"īǧmʿ al-mlfīn al-nṣyin aū akṯr fī ūḥdẗ al-tḥkm.",
Expand Down Expand Up @@ -3355,7 +3324,6 @@
"mrhban, {0}! marhaban bikum fi nitrusid!",
"tamkin aleanawin eind tasjil aldukhul li'iizhar khulasat RSS",
"'iiedadat",
"yughlaq",
"Nitrocid KS yuhaki nawat almustaqbila, Nitrocid Kernel.",
"wizarat aldifae API",
"laqad taeatalat safhat Nitrocid alrayiysiat watahtaj 'iilaa aleawdat 'iilaa alsudfati.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1770,37 +1770,8 @@
"您可以从 Nitrocid 完整版本附带的内核插件中获得额外的提示吗?",
"专业提示:你知道吗",
"键绑定",
"插入",
"消除",
"代替",
"全部替换",
"替换所有内容",
"号码信息",
"十六进制编辑器失败:",
"可用按键",
"用十六进制值写入字节数。",
"指定的字节数无效。",
"使用十六进制值写入字节数以替换 {0}。",
"写入要替换的十六进制值的字节数。",
"号码信息:",
"十六进制",
"八进制",
"数字",
"二进制",
"该键绑定不包含任何操作。",
"无法对空数组执行此操作。",
"进入...",
"删除线",
"停止输入",
"新队",
"文本编辑器失败:",
"写入要查找的字符串",
"写入替换字符串",
"线路",
"柱子",
"",
"垃圾桶",
"标签",
"无法对空行列表执行此操作。",
"未找到设置类型。",
"寻找一个选项",
Expand All @@ -1827,7 +1798,6 @@
"将设置保存至",
"正在加载设置...",
"正在重新加载设置...",
"在开发版本上禁用检查更新。",
"内核版本",
"内核API版本",
"主机ID",
Expand Down Expand Up @@ -1996,7 +1966,6 @@
"一行选择样式",
"两行选择样式",
"现代选择风格",
"餐桌选择款式",
"输出只能是一个字符",
"输出可以超过一个字符",
"将两个或更多文本文件合并到控制台中。",
Expand Down Expand Up @@ -3355,7 +3324,6 @@
"嗨,{0}!欢迎来到 Nitrocid!",
"登录时启用标题以显示 RSS 源",
"设置",
"关闭",
"Nitrocid KS 模拟我们未来的内核,Nitrocid Kernel。",
"修改 API",
"Nitrocid 主页已崩溃,需要恢复到 shell。",
Expand Down
Loading

0 comments on commit 87fc3ce

Please sign in to comment.