Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Robust.Shared/Localization/LocalizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Robust.Shared.Localization
internal abstract partial class LocalizationManager : ILocalizationManagerInternal
{
protected static readonly ResPath LocaleDirPath = new("/Locale");
protected static readonly ResPath UploadedDirPath = new("/Uploaded");

[Dependency] private readonly IConfigurationManager _configuration = default!;
[Dependency] private readonly IResourceManager _res = default!;
Expand Down Expand Up @@ -403,6 +404,20 @@ public List<CultureInfo> GetFoundCultures()
result.Add(CultureInfo.GetCultureInfo(cultureName, predefinedOnly: false));
}

var uploadedFiles = _res.ContentFindFiles(UploadedDirPath)
.Where(c => c.Filename.EndsWith(".ftl", StringComparison.InvariantCultureIgnoreCase));

foreach (var file in uploadedFiles)
{
var cultureName = Path.GetFileNameWithoutExtension(file.Filename);
if (CultureInfo.GetCultures(CultureTypes.AllCultures).Any(c => c.Name.Equals(cultureName, StringComparison.InvariantCultureIgnoreCase)))
{
var culture = CultureInfo.GetCultureInfo(cultureName, predefinedOnly: false);
if (!result.Contains(culture))
result.Add(culture);
}
}

return result;
}

Expand Down Expand Up @@ -485,10 +500,13 @@ private void _initData(IResourceManager resourceManager, CultureInfo culture, Fl
{
// Load data from .ftl files.
// Data is loaded from /Locale/<language-code>/*
// and from /Uploaded/**/Locale/<language-code>/*

var root = LocaleDirPath / culture.Name;

var files = resourceManager.ContentFindFiles(root)
.Concat(resourceManager.ContentFindFiles(UploadedDirPath)
.Where(c => c.CanonPath.Contains($"/Locale/{culture.Name}/", StringComparison.InvariantCultureIgnoreCase)))
.Where(c => c.Filename.EndsWith(".ftl", StringComparison.InvariantCultureIgnoreCase))
.ToArray();

Expand Down
14 changes: 14 additions & 0 deletions Robust.Shared/Upload/SharedNetworkResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Robust.Shared.Asynchronous;
using Robust.Shared.ContentPack;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Network;
using Robust.Shared.Network.Transfer;
Expand Down Expand Up @@ -38,6 +39,7 @@ public abstract class SharedNetworkResourceManager : IDisposable, IPostInjectIni
[Dependency] protected readonly IResourceManager ResourceManager = default!;
[Dependency] protected readonly ITransferManager TransferManager = default!;
[Dependency] protected readonly ILogManager LogManager = default!;
[Dependency] protected readonly ILocalizationManager LocalizationManager = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;

protected ISawmill Sawmill = default!;
Expand Down Expand Up @@ -112,9 +114,13 @@ protected virtual void ValidateUpload(uint size)
protected async Task<List<(ResPath Relative, byte[] Data)>> IngestFileStream(Stream stream)
{
var list = new List<(ResPath Relative, byte[] Data)>();
var anyLoc = false;

await foreach (var (relative, data) in ReadTransferStream(stream).ConfigureAwait(false))
{
if (relative.Extension == "ftl")
anyLoc = true;

Sawmill.Verbose($"Storing uploaded file: {relative} ({ByteHelpers.FormatBytes(data.Length)})");
_taskManager.RunOnMainThread(() =>
{
Expand All @@ -123,6 +129,14 @@ protected virtual void ValidateUpload(uint size)
list.Add((relative, data));
}

if (anyLoc)
{
_taskManager.RunOnMainThread(() =>
{
LocalizationManager.ReloadLocalizations();
});
}

return list;
}

Expand Down
Loading