-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Mod config settings now support translations. OWML will look for files named after the `TextTranslation.Language` enums in base game in a folder named `translations` where your mod is installed. Eg, `translations/english.json`. These files will follow the same format as New Horizons translations, and the `UIDictionary` will be used to store key-value pairs for your translation results. Translations support the `title` and `tooltip` fields for a setting, and if the title is absent it will use the setting's ID as a key. Check the OWML settings documentation for more info. - Added `dlcOnly` support to settings that should only appear when Echoes of the Eye is installed.
- Loading branch information
Showing
12 changed files
with
254 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
[*.{cs,vb}] | ||
#### Naming styles #### | ||
|
||
# Naming rules | ||
|
||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion | ||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface | ||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i | ||
|
||
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion | ||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types | ||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case | ||
|
||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion | ||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members | ||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case | ||
|
||
# Symbol specifications | ||
|
||
dotnet_naming_symbols.interface.applicable_kinds = interface | ||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||
dotnet_naming_symbols.interface.required_modifiers = | ||
|
||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum | ||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||
dotnet_naming_symbols.types.required_modifiers = | ||
|
||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method | ||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||
dotnet_naming_symbols.non_field_members.required_modifiers = | ||
|
||
# Naming styles | ||
|
||
dotnet_naming_style.begins_with_i.required_prefix = I | ||
dotnet_naming_style.begins_with_i.required_suffix = | ||
dotnet_naming_style.begins_with_i.word_separator = | ||
dotnet_naming_style.begins_with_i.capitalization = pascal_case | ||
|
||
dotnet_naming_style.pascal_case.required_prefix = | ||
dotnet_naming_style.pascal_case.required_suffix = | ||
dotnet_naming_style.pascal_case.word_separator = | ||
dotnet_naming_style.pascal_case.capitalization = pascal_case | ||
|
||
dotnet_naming_style.pascal_case.required_prefix = | ||
dotnet_naming_style.pascal_case.required_suffix = | ||
dotnet_naming_style.pascal_case.word_separator = | ||
dotnet_naming_style.pascal_case.capitalization = pascal_case | ||
dotnet_style_coalesce_expression = true:suggestion | ||
dotnet_style_operator_placement_when_wrapping = beginning_of_line | ||
tab_width = 4 | ||
indent_size = 4 | ||
end_of_line = crlf | ||
dotnet_style_null_propagation = true:suggestion | ||
indent_style = tab | ||
|
||
[*.cs] | ||
csharp_using_directive_placement = outside_namespace:silent | ||
csharp_prefer_simple_using_statement = true:suggestion | ||
csharp_prefer_braces = true:silent | ||
csharp_style_namespace_declarations = block_scoped:silent | ||
csharp_style_prefer_method_group_conversion = true:silent | ||
csharp_style_prefer_top_level_statements = true:silent | ||
csharp_style_expression_bodied_methods = false:silent | ||
csharp_style_expression_bodied_constructors = false:silent | ||
csharp_style_expression_bodied_operators = false:silent | ||
csharp_style_expression_bodied_properties = true:silent | ||
csharp_style_expression_bodied_indexers = true:silent | ||
csharp_style_expression_bodied_accessors = true:silent | ||
csharp_style_expression_bodied_lambdas = true:silent | ||
csharp_style_expression_bodied_local_functions = false:silent | ||
csharp_indent_labels = one_less_than_current |
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
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,7 @@ | ||
namespace OWML.Common.Interfaces | ||
{ | ||
public interface IModTranslations | ||
{ | ||
public string GetLocalizedString(string key); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Newtonsoft.Json.Linq; | ||
using OWML.Common; | ||
using OWML.Common.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace OWML.ModHelper.Menus | ||
{ | ||
public class ModTranslations : IModTranslations | ||
{ | ||
private Dictionary<TextTranslation.Language, Dictionary<string, string>> _translationTable = new(); | ||
|
||
private IModManifest _manifest; | ||
private IModConsole _console; | ||
|
||
// Menu translations are stored under UIDictionary | ||
// This means OWML config translations follow the New Horizons format | ||
public static readonly string UIDictionary = nameof(UIDictionary); | ||
|
||
private bool _initialized; | ||
|
||
public ModTranslations(IModManifest manifest, IModConsole console) | ||
{ | ||
_manifest = manifest; | ||
_console = console; | ||
} | ||
|
||
private void Init() | ||
{ | ||
try | ||
{ | ||
var translationsFolder = Path.Combine(_manifest.ModFolderPath, "translations"); | ||
foreach (TextTranslation.Language translation in Enum.GetValues(typeof(TextTranslation.Language))) | ||
{ | ||
var filename = Path.Combine(translationsFolder, $"{translation}.json"); | ||
if (File.Exists(filename)) | ||
{ | ||
var dict = JObject.Parse(File.ReadAllText(filename)).ToObject<Dictionary<string, object>>(); | ||
if (dict.ContainsKey(UIDictionary)) | ||
{ | ||
_translationTable[translation] = (Dictionary<string, string>)(dict[nameof(UIDictionary)] as JObject).ToObject(typeof(Dictionary<string, string>)); | ||
} | ||
} | ||
} | ||
_initialized = true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_console.WriteLine($"Failed to initialize mod option translations {ex}", MessageType.Error); | ||
} | ||
} | ||
|
||
public string GetLocalizedString(string key) | ||
{ | ||
if (!_initialized) | ||
{ | ||
Init(); | ||
} | ||
|
||
try | ||
{ | ||
if (key == null) return null; | ||
if (key == string.Empty) return string.Empty; | ||
|
||
if (!_translationTable.TryGetValue(TextTranslation.Get().m_language, out var dict)) | ||
{ | ||
// Default to English | ||
if (!_translationTable.TryGetValue(TextTranslation.Language.ENGLISH, out dict)) | ||
{ | ||
// Default to key | ||
return key; | ||
} | ||
} | ||
|
||
if (dict.TryGetValue(key, out var value)) | ||
{ | ||
return value; | ||
} | ||
else | ||
{ | ||
return key; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
_console.WriteLine($"Failed to load options translation: {ex}", MessageType.Error); | ||
return key; | ||
} | ||
} | ||
} | ||
} |
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.