Files
TTT/Locale/JsonLocalizerFactory.cs
2025-07-30 03:32:31 -07:00

29 lines
895 B
C#

using CounterStrikeSharp.API.Core.Translations;
using Microsoft.Extensions.Localization;
namespace TTT.Locale;
public class JsonLocalizerFactory : IStringLocalizerFactory {
private readonly string langPath;
public JsonLocalizerFactory() {
// Lang folder is in the root of the project
// keep moving up until we find it
var current = Directory.GetCurrentDirectory();
while (!Directory.Exists(Path.Combine(current, "lang"))) {
current = Directory.GetParent(current)?.FullName;
if (current == null)
throw new DirectoryNotFoundException("Could not find lang folder");
}
langPath = Path.Combine(current, "lang");
}
public IStringLocalizer Create(Type resourceSource) {
return new JsonStringLocalizer(langPath);
}
public IStringLocalizer Create(string baseName, string location) {
return new JsonStringLocalizer(langPath);
}
}