Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
fix: ensure ui falls back to english (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored May 11, 2024
1 parent 08ef354 commit 971a217
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions Jellyfin.Plugin.Themerr/Api/ThemerrController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public ActionResult GetTranslations()
// Get the current assembly
var assembly = Assembly.GetExecutingAssembly();

// Initialize the result dictionary
var result = new Dictionary<string, object>();

for (var i = 0; i < filePaths.Count; i++)
{
// construct the resource name
Expand All @@ -167,9 +170,6 @@ public ActionResult GetTranslations()
continue;
}

// Initialize the result dictionary
var result = new Dictionary<string, object>();

// read the resource content
using var reader = new StreamReader(stream);
var json = reader.ReadToEnd();
Expand All @@ -179,35 +179,33 @@ public ActionResult GetTranslations()

// Add the localized strings to the 'locale' key
result["locale"] = localizedStrings;
}

// Now get the fallback resource
var fallbackResourceName = "Jellyfin.Plugin.Themerr.Locale.en.json";
using var fallbackStream = assembly.GetManifestResourceStream(fallbackResourceName);
// Now get the fallback resource
var fallbackResourceName = "Jellyfin.Plugin.Themerr.Locale.en.json";
using var fallbackStream = assembly.GetManifestResourceStream(fallbackResourceName);

if (fallbackStream != null)
{
// read the fallback resource content
using var fallbackReader = new StreamReader(fallbackStream);
var fallbackJson = fallbackReader.ReadToEnd();
if (fallbackStream != null)
{
// read the fallback resource content
using var fallbackReader = new StreamReader(fallbackStream);
var fallbackJson = fallbackReader.ReadToEnd();

// deserialize the fallback JSON content into a dictionary
var fallbackLocalizedStrings =
JsonConvert.DeserializeObject<Dictionary<string, string>>(fallbackJson);
// deserialize the fallback JSON content into a dictionary
var fallbackLocalizedStrings =
JsonConvert.DeserializeObject<Dictionary<string, string>>(fallbackJson);

// Add the fallback localized strings to the 'fallback' key
result["fallback"] = fallbackLocalizedStrings;
}
else
{
_logger.LogError("Fallback locale resource does not exist: {ResourceName}", fallbackResourceName);
}

// return the result as a JSON object
return Ok(result);
// Add the fallback localized strings to the 'fallback' key
result["fallback"] = fallbackLocalizedStrings;
}
else
{
_logger.LogError("Fallback locale resource does not exist: {ResourceName}", fallbackResourceName);
return StatusCode(StatusCodes.Status500InternalServerError);
}

// return an error if we get this far
return StatusCode(StatusCodes.Status500InternalServerError);
// return the result as a JSON object
return Ok(result);
}

/// <summary>
Expand Down

0 comments on commit 971a217

Please sign in to comment.