Added more text content to the I18N system (#446)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2025-05-04 14:59:30 +02:00
1 parent cfc2103b43
commit 7a08baf99b
43 files changed
+3356 -354

No files matched your search

@@ -5,7 +5,7 @@ public class I18N : ILang
public static readonly I18N I = new();
private static readonly ILogger<I18N> LOG = Program.LOGGER_FACTORY.CreateLogger<I18N>();
private ILanguagePlugin language = PluginFactory.BaseLanguage;
private ILanguagePlugin? language = PluginFactory.BaseLanguage;
private I18N()
{
@@ -18,12 +18,18 @@ public class I18N : ILang
public string T(string fallbackEN)
{
LOG.LogWarning("Using I18N.I.T without namespace and type is probably wrong, because the I18N key collection process of the build system will not find those keys.");
return this.GetText(this.language, fallbackEN);
if(this.language is not null)
return this.GetText(this.language, fallbackEN);
return fallbackEN;
}
public string T(string fallbackEN, string? typeNamespace, string? typeName)
{
return this.GetText(this.language, fallbackEN, typeNamespace, typeName);
if(this.language is not null)
return this.GetText(this.language, fallbackEN, typeNamespace, typeName);
return fallbackEN;
}
#endregion
@@ -8,6 +8,8 @@ namespace AIStudio.Tools.PluginSystem;
/// </summary>
public abstract partial class PluginBase : IPluginMetadata
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginBase).Namespace, nameof(PluginBase));
private readonly IReadOnlyCollection<string> baseIssues;
protected readonly LuaState state;
@@ -155,21 +157,21 @@ public abstract partial class PluginBase : IPluginMetadata
{
if (!this.state.Environment["ID"].TryRead<string>(out var idText))
{
message = "The field ID does not exist or is not a valid string.";
message = TB("The field ID does not exist or is not a valid string.");
id = Guid.Empty;
return false;
}
if (!Guid.TryParse(idText, out id))
{
message = "The field ID is not a valid GUID / UUID. The ID must be formatted in the 8-4-4-4-12 format (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX).";
message = TB("The field ID is not a valid GUID / UUID. The ID must be formatted in the 8-4-4-4-12 format (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX).");
id = Guid.Empty;
return false;
}
if(id == Guid.Empty)
{
message = "The field ID is empty. The ID must be formatted in the 8-4-4-4-12 format (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX).";
message = TB("The field ID is empty. The ID must be formatted in the 8-4-4-4-12 format (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX).");
return false;
}
@@ -187,14 +189,14 @@ public abstract partial class PluginBase : IPluginMetadata
{
if (!this.state.Environment["NAME"].TryRead(out name))
{
message = "The field NAME does not exist or is not a valid string.";
message = TB("The field NAME does not exist or is not a valid string.");
name = string.Empty;
return false;
}
if(string.IsNullOrWhiteSpace(name))
{
message = "The field NAME is empty. The name must be a non-empty string.";
message = TB("The field NAME is empty. The name must be a non-empty string.");
return false;
}
@@ -212,14 +214,14 @@ public abstract partial class PluginBase : IPluginMetadata
{
if (!this.state.Environment["DESCRIPTION"].TryRead(out description))
{
message = "The field DESCRIPTION does not exist or is not a valid string.";
message = TB("The field DESCRIPTION does not exist or is not a valid string.");
description = string.Empty;
return false;
}
if(string.IsNullOrWhiteSpace(description))
{
message = "The field DESCRIPTION is empty. The description must be a non-empty string.";
message = TB("The field DESCRIPTION is empty. The description must be a non-empty string.");
return false;
}
@@ -237,21 +239,21 @@ public abstract partial class PluginBase : IPluginMetadata
{
if (!this.state.Environment["VERSION"].TryRead<string>(out var versionText))
{
message = "The field VERSION does not exist or is not a valid string.";
message = TB("The field VERSION does not exist or is not a valid string.");
version = PluginVersion.NONE;
return false;
}
if (!PluginVersion.TryParse(versionText, out version))
{
message = "The field VERSION is not a valid version number. The version number must be formatted as string in the major.minor.patch format (X.X.X).";
message = TB("The field VERSION is not a valid version number. The version number must be formatted as string in the major.minor.patch format (X.X.X).");
version = PluginVersion.NONE;
return false;
}
if(version == PluginVersion.NONE)
{
message = "The field VERSION is empty. The version number must be formatted as string in the major.minor.patch format (X.X.X).";
message = TB("The field VERSION is empty. The version number must be formatted as string in the major.minor.patch format (X.X.X).");
return false;
}
@@ -270,7 +272,7 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["AUTHORS"].TryRead<LuaTable>(out var authorsTable))
{
authors = [];
message = "The table AUTHORS does not exist or is using an invalid syntax.";
message = TB("The table AUTHORS does not exist or is using an invalid syntax.");
return false;
}
@@ -282,7 +284,7 @@ public abstract partial class PluginBase : IPluginMetadata
authors = authorList.ToArray();
if(authorList.Count == 0)
{
message = "The table AUTHORS is empty. At least one author must be specified.";
message = TB("The table AUTHORS is empty. At least one author must be specified.");
return false;
}
@@ -301,13 +303,13 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["SUPPORT_CONTACT"].TryRead(out contact))
{
contact = string.Empty;
message = "The field SUPPORT_CONTACT does not exist or is not a valid string.";
message = TB("The field SUPPORT_CONTACT does not exist or is not a valid string.");
return false;
}
if(string.IsNullOrWhiteSpace(contact))
{
message = "The field SUPPORT_CONTACT is empty. The support contact must be a non-empty string.";
message = TB("The field SUPPORT_CONTACT is empty. The support contact must be a non-empty string.");
return false;
}
@@ -326,14 +328,14 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["SOURCE_URL"].TryRead(out url))
{
url = string.Empty;
message = "The field SOURCE_URL does not exist or is not a valid string.";
message = TB("The field SOURCE_URL does not exist or is not a valid string.");
return false;
}
if (!url.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) && !url.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
{
url = string.Empty;
message = "The field SOURCE_URL is not a valid URL. The URL must start with 'http://' or 'https://'.";
message = TB("The field SOURCE_URL is not a valid URL. The URL must start with 'http://' or 'https://'.");
return false;
}
@@ -352,7 +354,7 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["CATEGORIES"].TryRead<LuaTable>(out var categoriesTable))
{
categories = [];
message = "The table CATEGORIES does not exist or is using an invalid syntax.";
message = TB("The table CATEGORIES does not exist or is using an invalid syntax.");
return false;
}
@@ -365,7 +367,7 @@ public abstract partial class PluginBase : IPluginMetadata
categories = categoryList.ToArray();
if(categoryList.Count == 0)
{
message = $"The table CATEGORIES is empty. At least one category is necessary. Valid categories are: {CommonTools.GetAllEnumValues(PluginCategory.NONE)}.";
message = string.Format(TB("The table CATEGORIES is empty. At least one category is necessary. Valid categories are: {0}."), CommonTools.GetAllEnumValues(PluginCategory.NONE));
return false;
}
@@ -384,7 +386,7 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["TARGET_GROUPS"].TryRead<LuaTable>(out var targetGroupsTable))
{
targetGroups = [];
message = "The table TARGET_GROUPS does not exist or is using an invalid syntax.";
message = TB("The table TARGET_GROUPS does not exist or is using an invalid syntax.");
return false;
}
@@ -397,7 +399,7 @@ public abstract partial class PluginBase : IPluginMetadata
targetGroups = targetGroupList.ToArray();
if(targetGroups.Length == 0)
{
message = "The table TARGET_GROUPS is empty or is not a valid table of strings. Valid target groups are: {CommonTools.GetAllEnumValues(PluginTargetGroup.NONE)}.";
message = string.Format(TB("The table TARGET_GROUPS is empty or is not a valid table of strings. Valid target groups are: {0}."), CommonTools.GetAllEnumValues(PluginTargetGroup.NONE));
return false;
}
@@ -416,7 +418,7 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["IS_MAINTAINED"].TryRead(out isMaintained))
{
isMaintained = false;
message = "The field IS_MAINTAINED does not exist or is not a valid boolean.";
message = TB("The field IS_MAINTAINED does not exist or is not a valid boolean.");
return false;
}
@@ -435,7 +437,7 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["DEPRECATION_MESSAGE"].TryRead(out deprecationMessage))
{
deprecationMessage = string.Empty;
message = "The field DEPRECATION_MESSAGE does not exist, is not a valid string. This message is optional: use an empty string to indicate that the plugin is not deprecated.";
message = TB("The field DEPRECATION_MESSAGE does not exist, is not a valid string. This message is optional: use an empty string to indicate that the plugin is not deprecated.");
return false;
}
@@ -453,7 +455,7 @@ public abstract partial class PluginBase : IPluginMetadata
{
if (!this.state.Environment["UI_TEXT_CONTENT"].TryRead<LuaTable>(out var textTable))
{
message = "The UI_TEXT_CONTENT table does not exist or is not a valid table.";
message = TB("The UI_TEXT_CONTENT table does not exist or is not a valid table.");
pluginContent = [];
return false;
}
@@ -2,37 +2,39 @@ namespace AIStudio.Tools.PluginSystem;
public static class PluginCategoryExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginCategoryExtensions).Namespace, nameof(PluginCategoryExtensions));
public static string GetName(this PluginCategory type) => type switch
{
PluginCategory.NONE => "None",
PluginCategory.CORE => "AI Studio Core",
PluginCategory.NONE => TB("None"),
PluginCategory.CORE => TB("AI Studio Core"),
PluginCategory.BUSINESS => "Business",
PluginCategory.INDUSTRY => "Industry",
PluginCategory.UTILITY => "Utility",
PluginCategory.SOFTWARE_DEVELOPMENT => "Software Development",
PluginCategory.GAMING => "Gaming",
PluginCategory.EDUCATION => "Education",
PluginCategory.ENTERTAINMENT => "Entertainment",
PluginCategory.SOCIAL => "Social",
PluginCategory.SHOPPING => "Shopping",
PluginCategory.TRAVEL => "Travel",
PluginCategory.HEALTH => "Health",
PluginCategory.FITNESS => "Fitness",
PluginCategory.FOOD => "Food",
PluginCategory.PARTY => "Party",
PluginCategory.SPORTS => "Sports",
PluginCategory.NEWS => "News",
PluginCategory.WEATHER => "Weather",
PluginCategory.MUSIC => "Music",
PluginCategory.POLITICAL => "Political",
PluginCategory.SCIENCE => "Science",
PluginCategory.TECHNOLOGY => "Technology",
PluginCategory.ART => "Art",
PluginCategory.FICTION => "Fiction",
PluginCategory.WRITING => "Writing",
PluginCategory.CONTENT_CREATION => "Content Creation",
PluginCategory.BUSINESS => TB("Business"),
PluginCategory.INDUSTRY => TB("Industry"),
PluginCategory.UTILITY => TB("Utility"),
PluginCategory.SOFTWARE_DEVELOPMENT => TB("Software Development"),
PluginCategory.GAMING => TB("Gaming"),
PluginCategory.EDUCATION => TB("Education"),
PluginCategory.ENTERTAINMENT => TB("Entertainment"),
PluginCategory.SOCIAL => TB("Social"),
PluginCategory.SHOPPING => TB("Shopping"),
PluginCategory.TRAVEL => TB("Travel"),
PluginCategory.HEALTH => TB("Health"),
PluginCategory.FITNESS => TB("Fitness"),
PluginCategory.FOOD => TB("Food"),
PluginCategory.PARTY => TB("Party"),
PluginCategory.SPORTS => TB("Sports"),
PluginCategory.NEWS => TB("News"),
PluginCategory.WEATHER => TB("Weather"),
PluginCategory.MUSIC => TB("Music"),
PluginCategory.POLITICAL => TB("Political"),
PluginCategory.SCIENCE => TB("Science"),
PluginCategory.TECHNOLOGY => TB("Technology"),
PluginCategory.ART => TB("Art"),
PluginCategory.FICTION => TB("Fiction"),
PluginCategory.WRITING => TB("Writing"),
PluginCategory.CONTENT_CREATION => TB("Content Creation"),
_ => "Unknown plugin category",
_ => TB("Unknown plugin category"),
};
}
@@ -4,6 +4,7 @@ namespace AIStudio.Tools.PluginSystem;
public sealed class PluginLanguage : PluginBase, ILanguagePlugin
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginLanguage).Namespace, nameof(PluginLanguage));
private static readonly ILogger<PluginLanguage> LOGGER = Program.LOGGER_FACTORY.CreateLogger<PluginLanguage>();
private readonly Dictionary<string, string> content = [];
@@ -53,28 +54,28 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
{
if (!this.state.Environment["IETF_TAG"].TryRead(out readLangCultureTag))
{
message = "The field IETF_TAG does not exist or is not a valid string.";
message = TB("The field IETF_TAG does not exist or is not a valid string.");
readLangCultureTag = string.Empty;
return false;
}
if (string.IsNullOrWhiteSpace(readLangCultureTag))
{
message = "The field IETF_TAG is empty. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
message = TB("The field IETF_TAG is empty. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.");
readLangCultureTag = string.Empty;
return false;
}
if (readLangCultureTag.Length != 5)
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
message = TB("The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.");
readLangCultureTag = string.Empty;
return false;
}
if (readLangCultureTag[2] != '-')
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
message = TB("The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.");
readLangCultureTag = string.Empty;
return false;
}
@@ -83,7 +84,7 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
for (var i = 0; i < 2; i++)
if (!char.IsLower(readLangCultureTag[i]))
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
message = TB("The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.");
readLangCultureTag = string.Empty;
return false;
}
@@ -92,7 +93,7 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
for (var i = 3; i < 5; i++)
if (!char.IsUpper(readLangCultureTag[i]))
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
message = TB("The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.");
readLangCultureTag = string.Empty;
return false;
}
@@ -105,14 +106,14 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
{
if (!this.state.Environment["LANG_NAME"].TryRead(out readLangName))
{
message = "The field LANG_NAME does not exist or is not a valid string.";
message = TB("The field LANG_NAME does not exist or is not a valid string.");
readLangName = string.Empty;
return false;
}
if (string.IsNullOrWhiteSpace(readLangName))
{
message = "The field LANG_NAME is empty. Use a valid language name.";
message = TB("The field LANG_NAME is empty. Use a valid language name.");
readLangName = string.Empty;
return false;
}
@@ -2,24 +2,26 @@ namespace AIStudio.Tools.PluginSystem;
public static class PluginTargetGroupExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginTargetGroupExtensions).Namespace, nameof(PluginTargetGroupExtensions));
public static string Name(this PluginTargetGroup group) => group switch
{
PluginTargetGroup.NONE => "No target group",
PluginTargetGroup.NONE => TB("No target group"),
PluginTargetGroup.EVERYONE => "Everyone",
PluginTargetGroup.CHILDREN => "Children",
PluginTargetGroup.TEENAGERS => "Teenagers",
PluginTargetGroup.STUDENTS => "Students",
PluginTargetGroup.ADULTS => "Adults",
PluginTargetGroup.EVERYONE => TB("Everyone"),
PluginTargetGroup.CHILDREN => TB("Children"),
PluginTargetGroup.TEENAGERS => TB("Teenagers"),
PluginTargetGroup.STUDENTS => TB("Students"),
PluginTargetGroup.ADULTS => TB("Adults"),
PluginTargetGroup.INDUSTRIAL_WORKERS => "Industrial workers",
PluginTargetGroup.OFFICE_WORKERS => "Office workers",
PluginTargetGroup.BUSINESS_PROFESSIONALS => "Business professionals",
PluginTargetGroup.SOFTWARE_DEVELOPERS => "Software developers",
PluginTargetGroup.SCIENTISTS => "Scientists",
PluginTargetGroup.TEACHERS => "Teachers",
PluginTargetGroup.ARTISTS => "Artists",
PluginTargetGroup.INDUSTRIAL_WORKERS => TB("Industrial workers"),
PluginTargetGroup.OFFICE_WORKERS => TB("Office workers"),
PluginTargetGroup.BUSINESS_PROFESSIONALS => TB("Business professionals"),
PluginTargetGroup.SOFTWARE_DEVELOPERS => TB("Software developers"),
PluginTargetGroup.SCIENTISTS => TB("Scientists"),
PluginTargetGroup.TEACHERS => TB("Teachers"),
PluginTargetGroup.ARTISTS => TB("Artists"),
_ => "Unknown target group",
_ => TB("Unknown target group"),
};
}
@@ -2,14 +2,16 @@ namespace AIStudio.Tools.PluginSystem;
public static class PluginTypeExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginTypeExtensions).Namespace, nameof(PluginTypeExtensions));
public static string GetName(this PluginType type) => type switch
{
PluginType.LANGUAGE => "Language plugin",
PluginType.ASSISTANT => "Assistant plugin",
PluginType.CONFIGURATION => "Configuration plugin",
PluginType.THEME => "Theme plugin",
PluginType.LANGUAGE => TB("Language plugin"),
PluginType.ASSISTANT => TB("Assistant plugin"),
PluginType.CONFIGURATION => TB("Configuration plugin"),
PluginType.THEME => TB("Theme plugin"),
_ => "Unknown plugin type",
_ => TB("Unknown plugin type"),
};
public static string GetDirectory(this PluginType type) => type switch