diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 4a64da9..7c4c998 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -57,6 +57,18 @@ dotnet build dotnet test ``` +### Settings page translations + +Settings strings live in `TheIntroDB/Configuration/locales/`. Use `en.json` as +the reference for translation keys and keep placeholders such as `{count}` +unchanged. Name a new file after its language or locale (for example, `fr.json` +or `fr-CA.json`). Locale files are embedded automatically; missing translations +fall back to English. + +Run `node --test tests/settings-localization.test.cjs` to check the UI +translations, and `dotnet test` to verify packaged locale resolution. + + ## Pull Request Guidelines 1. **Create a Branch**: Create a descriptive branch name for your changes (e.g., `feat/add-new-feature` or `fix/issue-description`). diff --git a/TheIntroDB.Tests/SettingsLocalizationTests.cs b/TheIntroDB.Tests/SettingsLocalizationTests.cs new file mode 100644 index 0000000..72b2c3c --- /dev/null +++ b/TheIntroDB.Tests/SettingsLocalizationTests.cs @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Copyright (C) 2026 TheIntroDB + +using System.Collections.Generic; +using TheIntroDB.Api; +using Xunit; + +namespace TheIntroDB.Tests; + +public sealed class SettingsLocalizationTests +{ + [Theory] + [InlineData("zh-CN", true)] + [InlineData("zh_CN", true)] + [InlineData("zh-Hans-CN", true)] + [InlineData("zh-SG", true)] + [InlineData("zh", true)] + [InlineData("zh-TW", false)] + [InlineData("en-US", false)] + [InlineData("fr-FR", false)] + [InlineData("", false)] + [InlineData(@"..\configPage", false)] + public void LoadsEmbeddedDictionaryForRequestedLocale(string locale, bool isSimplifiedChinese) + { + var service = new SettingsLocalizationService(); + var messages = Assert.IsType>( + service.Get(new SettingsLocalizationService.GetTranslations { Locale = locale })); + + Assert.Equal(isSimplifiedChinese ? "\u4fdd\u5b58" : "Save", messages["save"]); + Assert.Contains("{count}", messages["clearedEntries"]); + Assert.True(messages.Count > 100); + } +} diff --git a/TheIntroDB/Api/SettingsLocalizationService.cs b/TheIntroDB/Api/SettingsLocalizationService.cs new file mode 100644 index 0000000..ed0b78d --- /dev/null +++ b/TheIntroDB/Api/SettingsLocalizationService.cs @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Copyright (C) 2026 TheIntroDB + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json; +using MediaBrowser.Controller.Net; +using MediaBrowser.Model.Services; + +namespace TheIntroDB.Api +{ + [Authenticated(Roles = "Admin")] + public sealed class SettingsLocalizationService : IService + { + private const string Prefix = "TheIntroDB.SettingsLocales."; + private const string Suffix = ".json"; + private static readonly System.Reflection.Assembly Assembly = typeof(SettingsLocalizationService).Assembly; + private static readonly Dictionary LocaleResources = Assembly.GetManifestResourceNames() + .Where(name => name.StartsWith(Prefix, StringComparison.Ordinal) && name.EndsWith(Suffix, StringComparison.Ordinal)) + .ToDictionary(name => name.Substring(Prefix.Length, name.Length - Prefix.Length - Suffix.Length), + name => name, StringComparer.OrdinalIgnoreCase); + + [Route("/TheIntroDB/Settings/Translations", "GET", Summary = "Get settings-page translations")] + public sealed class GetTranslations : IReturn> + { + public string Locale { get; set; } + } + + public object Get(GetTranslations request) + { + var messages = ReadLocale("en"); + var locale = request.Locale?.Trim().Replace('_', '-') ?? string.Empty; + var separator = locale.IndexOf('-'); + var language = separator < 0 ? locale : locale.Substring(0, separator); + + // Neutral and Simplified Chinese variants use the existing zh-CN translation. + var simplifiedChinese = locale.Equals("zh", StringComparison.OrdinalIgnoreCase) + || locale.Equals("zh-SG", StringComparison.OrdinalIgnoreCase) + || locale.Equals("zh-Hans", StringComparison.OrdinalIgnoreCase) + || locale.StartsWith("zh-Hans-", StringComparison.OrdinalIgnoreCase); + var selected = LocaleResources.ContainsKey(locale) + ? locale + : simplifiedChinese ? "zh-CN" : language; + if (!selected.Equals("en", StringComparison.OrdinalIgnoreCase)) + { + foreach (var entry in ReadLocale(selected)) + { + messages[entry.Key] = entry.Value; + } + } + + return messages; + } + + private static Dictionary ReadLocale(string locale) + { + if (!LocaleResources.TryGetValue(locale, out var resource)) + { + return new Dictionary(); + } + + using var stream = Assembly.GetManifestResourceStream(resource); + return JsonSerializer.Deserialize>(stream) + ?? new Dictionary(); + } + } +} diff --git a/TheIntroDB/Configuration/configPage.html b/TheIntroDB/Configuration/configPage.html index f96f0cf..e5d2338 100644 --- a/TheIntroDB/Configuration/configPage.html +++ b/TheIntroDB/Configuration/configPage.html @@ -20,184 +20,184 @@

TheIntroDB

- Segment data (intro, recap, credits, preview) is fetched from + Segment data (intro, recap, credits, preview) is fetched from TheIntroDB API - (v4) using each item's TVDB, TMDB or IMDB ID. TVDB is preferred: it is the API's identity, and it is what lets series with a non-default display order (DVD, absolute) resolve to the right episode. Segments are not loaded when you press play; run the TheIntroDB media segment scan scheduled task to populate them. + (v4) using each item's TVDB, TMDB or IMDB ID. TVDB is preferred: it is the API's identity, and it is what lets series with a non-default display order (DVD, absolute) resolve to the right episode. Segments are not loaded when you press play; run the TheIntroDB media segment scan scheduled task to populate them.

-

Connection

+

Connection

- + -
Optional Bearer token; when set, your pending and accepted submissions are weighted higher in results, and requests use the signed-in rate limits (120 requests per 10 seconds, 100,000 lookups per day instead of 30 and 5,000). A key is what lets a large library scan finish in one run.
+
Optional Bearer token; when set, your pending and accepted submissions are weighted higher in results, and requests use the signed-in rate limits (120 requests per 10 seconds, 100,000 lookups per day instead of 30 and 5,000). A key is what lets a large library scan finish in one run.
-

Scan scope

+

Scan scope

- -
All media
- - -
Whitelisting a library scans all movies and episodes inside it. Selecting individual movies or shows only scans those specific items. Any media outside the selected libraries or items is left unchanged.
+ +
All media
+ + +
Whitelisting a library scans all movies and episodes inside it. Selecting individual movies or shows only scans those specific items. Any media outside the selected libraries or items is left unchanged.
- - + +
-
Items TheIntroDB has no data for are skipped for 14 days to save API requests. If you just submitted segments on theintrodb.org, clear the cache and run the Media segment scan to pull them into your library.
+
Items TheIntroDB has no data for are skipped for 14 days to save API requests. If you just submitted segments on theintrodb.org, clear the cache and run the Media segment scan to pull them into your library.
-

Segments

+

Segments

-
Include intro segments from TheIntroDB in Emby media processing.
+
Include intro segments from TheIntroDB in Emby media processing.
-
Include recap segments from TheIntroDB.
+
Include recap segments from TheIntroDB.
-
Include credits/outro segments from TheIntroDB.
+
Include credits/outro segments from TheIntroDB.
-
Include preview segments from TheIntroDB.
+
Include preview segments from TheIntroDB.
-
When enabled, readable chapter entries are created alongside native markers (IntroStart, CreditsStart). Recaps and Previews have no native marker support in Emby and will be invisible without chapters. Disable this to hide the identification string from chapter names.
+
When enabled, readable chapter entries are created alongside native markers (IntroStart, CreditsStart). Recaps and Previews have no native marker support in Emby and will be invisible without chapters. Disable this to hide the identification string from chapter names.
-

Marker protection

+

Marker protection

-
Recommended. Any existing complete or partial native intro marker prevents TheIntroDB from changing that intro pair.
+
Recommended. Any existing complete or partial native intro marker prevents TheIntroDB from changing that intro pair.
-
Recommended. An existing native credits marker remains authoritative.
+
Recommended. An existing native credits marker remains authoritative.
-
Off by default. Only chapters carrying a matching durable TheIntroDB ownership token are removed before updated markers are applied. Native, manual, legacy and third-party chapters remain unchanged.
+
Off by default. Only chapters carrying a matching durable TheIntroDB ownership token are removed before updated markers are applied. Native, manual, legacy and third-party chapters remain unchanged.
-

Scanning behavior

+

Scanning behavior

-
When enabled, items that already have segments are skipped to avoid refetching, until their own segments are due for a refresh.
+
When enabled, items that already have segments are skipped to avoid refetching, until their own segments are due for a refresh.
- + -
Items with segments from TheIntroDB are fetched again after this many days, so corrected submissions arrive. Default 30. 0 never refreshes.
+
Items with segments from TheIntroDB are fetched again after this many days, so corrected submissions arrive. Default 30. 0 never refreshes.
-
When enabled, segments are fetched for newly added items — after their metadata download, and on playback start. Existing segments are kept or refreshed as configured above.
+
When enabled, segments are fetched for newly added items — after their metadata download, and on playback start. Existing segments are kept or refreshed as configured above.
- + -
Bounds large scans: how many API lookups a single run may perform. Default 400. Zero disables API lookups for the task. Large libraries may need more; re-running the scan continues where it left off.
+
Bounds large scans: how many API lookups a single run may perform. Default 400. Zero disables API lookups for the task. Large libraries may need more; re-running the scan continues where it left off.
-

Privacy & logging

+

Privacy & logging

-
When enabled, anonymous usage metrics may be collected to help improve the plugin.
+
When enabled, anonymous usage metrics may be collected to help improve the plugin.
-
When enabled, plugin logs are written to a separate file (data/theintrodb/theintrodb.log) instead of the main Emby log.
+
When enabled, plugin logs are written to a separate file (data/theintrodb/theintrodb.log) instead of the main Emby log.
-

Maintenance

+

Maintenance

- + -
How often the plugin checks items it has segments for and restores TheIntroDB markers that Emby may have overwritten (e.g. when Emby regenerates placeholder chapters for files without embedded chapters). Set to 0 to disable automatic repair.
+
How often the plugin checks items it has segments for and restores TheIntroDB markers that Emby may have overwritten (e.g. when Emby regenerates placeholder chapters for files without embedded chapters). Set to 0 to disable automatic repair.
-

Tip: Emby's library setting "Generate chapters for videos that don't contain embedded chapter information" (Dashboard → Libraries → edit a library) can overwrite TheIntroDB markers on files without embedded chapters. Disabling it there prevents the overwrite entirely.

+

Tip: Emby's library setting "Generate chapters for videos that don't contain embedded chapter information" (Dashboard → Libraries → edit a library) can overwrite TheIntroDB markers on files without embedded chapters. Disabling it there prevents the overwrite entirely.

-

Debug

+

Debug

- + -
Loads stored segments for a specific item from the local DB.
+
Loads stored segments for a specific item from the local DB.

             
@@ -207,23 +207,23 @@

Debug

- -

Choose Libraries

+ +

Choose Libraries

- - + +
- -
Open a library to browse its movies and shows. Inside a library, you can whitelist the whole folder or pick individual movies and shows.
+ +
Open a library to browse its movies and shows. Inside a library, you can whitelist the whole folder or pick individual movies and shows.
- +
-
Loading libraries...
+
Loading libraries...
@@ -231,8 +231,8 @@

Choose Libraries