Match any arbitrary assembly for localisations

This commit is contained in:
smoogipoo 2021-06-14 17:47:31 +09:00
parent ebe850fe9f
commit b327baa4de

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Resources;
using System.Threading.Tasks;
using osu.Framework.Localisation;
@ -34,7 +35,29 @@ namespace osu.Game.Localisation
lock (resourceManagers)
{
if (!resourceManagers.TryGetValue(ns, out var manager))
resourceManagers[ns] = manager = new ResourceManager(ns, GetType().Assembly);
{
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
// Traverse backwards through periods in the namespace to find a matching assembly.
string assemblyName = ns;
while (!string.IsNullOrEmpty(assemblyName))
{
var matchingAssembly = loadedAssemblies.FirstOrDefault(asm => asm.GetName().Name == assemblyName);
if (matchingAssembly != null)
{
resourceManagers[ns] = manager = new ResourceManager(ns, matchingAssembly);
break;
}
int lastIndex = Math.Max(0, assemblyName.LastIndexOf('.'));
assemblyName = assemblyName.Substring(0, lastIndex);
}
}
if (manager == null)
return null;
try
{