feat(01-05): implement TranslationSource singleton + EN/FR resx files
- TranslationSource singleton with INotifyPropertyChanged indexer binding - PropertyChanged fires with string.Empty on culture switch (signals all bindings refresh) - Missing key returns [key] placeholder (prevents null in WPF bindings) - Strings.resx with 27 Phase 1 UI string keys (EN) - Strings.fr.resx with same 27 keys stubbed with EN text (FR completeness Phase 5) - Strings.Designer.cs ResourceManager for dotnet build compatibility - SharepointToolbox.csproj updated with EmbeddedResource metadata
This commit is contained in:
38
SharepointToolbox/Localization/TranslationSource.cs
Normal file
38
SharepointToolbox/Localization/TranslationSource.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Resources;
|
||||
|
||||
namespace SharepointToolbox.Localization;
|
||||
|
||||
/// <summary>
|
||||
/// Singleton INotifyPropertyChanged string lookup enabling runtime culture switching without restart.
|
||||
/// WPF bindings use: Source={x:Static loc:TranslationSource.Instance}, Path=[key]
|
||||
/// On CurrentCulture change, fires PropertyChanged with empty string to signal all properties changed,
|
||||
/// which causes WPF to re-evaluate all bindings to this source.
|
||||
/// </summary>
|
||||
public class TranslationSource : INotifyPropertyChanged
|
||||
{
|
||||
public static readonly TranslationSource Instance = new();
|
||||
|
||||
private ResourceManager _resourceManager = Strings.ResourceManager;
|
||||
private CultureInfo _currentCulture = CultureInfo.CurrentUICulture;
|
||||
|
||||
private TranslationSource() { }
|
||||
|
||||
public string this[string key] =>
|
||||
_resourceManager.GetString(key, _currentCulture) ?? $"[{key}]";
|
||||
|
||||
public CultureInfo CurrentCulture
|
||||
{
|
||||
get => _currentCulture;
|
||||
set
|
||||
{
|
||||
if (Equals(_currentCulture, value)) return;
|
||||
_currentCulture = value;
|
||||
Thread.CurrentThread.CurrentUICulture = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(string.Empty));
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
}
|
||||
Reference in New Issue
Block a user