mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 19:33:20 +08:00
Merge pull request #13490 from smoogipoo/arbitrary-localisation-assembly
Match any arbitrary assembly for localisations
This commit is contained in:
commit
75b5b50aee
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Resources;
|
using System.Resources;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
@ -34,7 +35,29 @@ namespace osu.Game.Localisation
|
|||||||
lock (resourceManagers)
|
lock (resourceManagers)
|
||||||
{
|
{
|
||||||
if (!resourceManagers.TryGetValue(ns, out var manager))
|
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
|
try
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user