-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonLocalizationOptions.cs
More file actions
126 lines (113 loc) · 4.3 KB
/
Copy pathJsonLocalizationOptions.cs
File metadata and controls
126 lines (113 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) 2025 Nikolaos Protopapas
// Licensed under the MIT License
using System.Globalization;
using System.Reflection;
using LocalizationManager.JsonLocalization.Core;
using LocalizationManager.JsonLocalization.Ota;
namespace LocalizationManager.JsonLocalization;
/// <summary>
/// Options for configuring JSON localization.
/// </summary>
public class JsonLocalizationOptions
{
/// <summary>
/// Path to the directory containing JSON resource files.
/// Used when loading resources from the file system.
/// Default: "Resources"
/// </summary>
public string ResourcesPath { get; set; } = "Resources";
/// <summary>
/// Base name of the resource files (without extension or culture code).
/// Example: "strings" produces "strings.json", "strings.fr.json", etc.
/// Default: "strings"
/// </summary>
public string BaseName { get; set; } = "strings";
/// <summary>
/// Whether to load resources from embedded assembly resources instead of the file system.
/// When true, ResourcesPath is used as the namespace prefix.
/// Default: false
/// </summary>
public bool UseEmbeddedResources { get; set; } = false;
/// <summary>
/// The assembly to load embedded resources from.
/// Only used when UseEmbeddedResources is true.
/// Default: Entry assembly
/// </summary>
public Assembly? ResourceAssembly { get; set; }
/// <summary>
/// The default culture to use when the current culture is not available.
/// Default: InvariantCulture
/// </summary>
public CultureInfo DefaultCulture { get; set; } = CultureInfo.InvariantCulture;
/// <summary>
/// Enable i18next compatibility mode.
/// When true, supports i18next-style interpolation ({{var}}) and plural suffixes.
/// Default: false
/// </summary>
public bool I18nextCompatible { get; set; } = false;
/// <summary>
/// Whether to use nested key structure in JSON files.
/// When true, keys like "Errors.NotFound" map to nested objects.
/// Default: true
/// </summary>
public bool UseNestedKeys { get; set; } = true;
/// <summary>
/// OTA (Over-The-Air) localization options.
/// When configured, translations are fetched from LRM Cloud at runtime.
/// </summary>
public OtaOptions? Ota { get; set; }
/// <summary>
/// Configures OTA (Over-The-Air) localization with LRM Cloud.
/// Translations are fetched from the cloud at runtime and updated periodically.
/// </summary>
/// <param name="endpoint">The LRM Cloud endpoint URL (default: https://lrm-cloud.com)</param>
/// <param name="apiKey">The API key for authentication (must start with lrm_)</param>
/// <param name="project">Project path: @username/project for user projects, or org/project for organizations</param>
/// <returns>This options instance for chaining.</returns>
/// <example>
/// <code>
/// services.AddJsonLocalization(options => {
/// options.UseOta(
/// endpoint: "https://lrm-cloud.com",
/// apiKey: "lrm_your_api_key",
/// project: "@username/my-project"
/// );
/// });
/// </code>
/// </example>
public JsonLocalizationOptions UseOta(string endpoint, string apiKey, string project)
{
Ota = new OtaOptions
{
Endpoint = endpoint,
ApiKey = apiKey,
Project = project
};
return this;
}
/// <summary>
/// Configures OTA (Over-The-Air) localization with detailed options.
/// </summary>
/// <param name="configure">Action to configure OTA options.</param>
/// <returns>This options instance for chaining.</returns>
public JsonLocalizationOptions UseOta(Action<OtaOptions> configure)
{
Ota = new OtaOptions();
configure(Ota);
return this;
}
/// <summary>
/// Gets the JSON format configuration based on these options.
/// </summary>
internal JsonFormatConfiguration GetFormatConfiguration()
{
return new JsonFormatConfiguration
{
BaseName = BaseName,
UseNestedKeys = UseNestedKeys,
I18nextCompatible = I18nextCompatible,
IncludeMeta = false, // Not needed for reading
PreserveComments = false // Not needed for reading
};
}
}