mirror of
https://github.com/ppy/osu
synced 2025-01-11 08:39:31 +00:00
Match any arbitrary assembly for localisations
This commit is contained in:
parent
ebe850fe9f
commit
b327baa4de
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user