Skip to content

Commit

Permalink
fix localization
Browse files Browse the repository at this point in the history
  • Loading branch information
kfrancis committed May 24, 2023
1 parent b5e0b7d commit b2b4453
Show file tree
Hide file tree
Showing 28 changed files with 213 additions and 223 deletions.
4 changes: 3 additions & 1 deletion src/NuSocial.Blazor/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using CommunityToolkit.Maui;
using Microsoft.Extensions.Logging;
using NuSocial.Blazor.Data;

namespace NuSocial.Blazor
Expand All @@ -10,6 +11,7 @@ public static MauiApp CreateMauiApp()
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ public LocalizedString GetValue(string resourceKey)
CultureInfo.CurrentCulture = CurrentCulture;
CultureInfo.CurrentUICulture = CurrentCulture;

return _localizer[resourceKey];
var loc = _localizer[resourceKey];
if (loc.ResourceNotFound)
{
Debug.WriteLine($"Resource not found: {resourceKey}");
loc = new LocalizedString(loc.Name, $"[{resourceKey}]", loc.ResourceNotFound);
}
return loc;
}

internal static object GetInstance(IServiceProvider serviceProvider)
Expand Down
12 changes: 10 additions & 2 deletions src/NuSocial.Core/Localization/NuSocial/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@
"AboutPlaceholder": "Add something interesting about you ..",
"AccountId": "Account ID",
"AccountKeyPlaceholder": "nsec1...",
"NuSocial": "NuSocial",
"NuSocial": "NuSocial 123",
"TapToRegenerate": "Tap to regenerate",
"WelcomeText": "#nostr NuSocial: Your Universe, Nu Connections",
"NoRecentPosts": "No recent posts",
"Enum_My": "My",
"Enum_Mutual": "Mutual"
"Enum_Mutual": "Mutual",
"Unread": "Unread",
"Reply": "Reply",
"TestMode": "Test Mode",
"Logout": "Logout",
"Profile": "Profile",
"Home": "Home",
"Settings": "Settings",
"Messages": "Messages"
}
}
6 changes: 3 additions & 3 deletions src/NuSocial.Core/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ public string PrivateKeyString

public class Profile
{
private string? _picture = "https://placehold.co/60x60";
private string? _picture = "https://placehold.co/60x60.png";

public string Name { get; internal set; } = string.Empty;
public string? DisplayName { get; internal set; }
public string? Picture
{
get
{
if (string.IsNullOrEmpty(_picture) || (_picture.Equals("https://placehold.co/60x60", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(Name)))
if (string.IsNullOrEmpty(_picture) || (_picture.Equals("https://placehold.co/60x60.png", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(Name)))
{
_picture = $"https://placehold.co/60x60?text={Name}";
_picture = $"https://placehold.co/60x60.png?text={Name}";
}
return _picture;
}
Expand Down
12 changes: 6 additions & 6 deletions src/NuSocial.Core/NuSocial.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Localization\NuSocial\en.json" />
<EmbeddedResource Include="Localization\NuSocial\fr.json" />
<EmbeddedResource Include="Localization\NuSocial\*.json" />
<Content Remove="Localization\NuSocial\*.json" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -60,10 +60,10 @@
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.4" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="Telerik.UI.for.Maui" Version="5.1.0" />
<PackageReference Include="Volo.Abp.Core" Version="7.1.1" />
<PackageReference Include="Volo.Abp.Localization" Version="7.1.1" />
<PackageReference Include="Volo.Abp.Localization.Abstractions" Version="7.1.1" />
<PackageReference Include="Volo.Abp.Validation" Version="7.1.1" />
<PackageReference Include="Volo.Abp.Core" Version="7.2.2" />
<PackageReference Include="Volo.Abp.Localization" Version="7.2.2" />
<PackageReference Include="Volo.Abp.Localization.Abstractions" Version="7.2.2" />
<PackageReference Include="Volo.Abp.Validation" Version="7.2.2" />
<PackageReference Include="Xam.Plugin.Media" Version="5.0.1" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/NuSocial.Core/NuSocialCoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
Configure<AbpVirtualFileSystemOptions>(options =>
{
// "YourRootNameSpace" is the root namespace of your project. It can be empty if your root namespace is empty.
options.FileSets.AddEmbedded<NuSocialCoreModule>();
options.FileSets.AddEmbedded<NuSocialCoreModule>("NuSocial.Core");
});

Configure<AbpLocalizationOptions>(options =>
Expand Down
8 changes: 4 additions & 4 deletions src/NuSocial.Core/ViewModels/AgreeViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using NuSocial.Core.ViewModel;
using Volo.Abp.DependencyInjection;

namespace NuSocial.ViewModels;
Expand All @@ -7,7 +6,7 @@ public partial class AgreeViewModel : BaseViewModel, ITransientDependency
{
public AgreeViewModel(IDialogService dialogService, INavigationService navigationService) : base(dialogService, navigationService)
{
Title = L["EULA"];

}

[ObservableProperty]
Expand Down Expand Up @@ -56,9 +55,10 @@ private Task DisagreeAsync()
});
}

public override Task OnFirstAppear()
public override Task InitializeAsync()
{
Title = L["EULA"];
Eula = L["AgreementText"];
return Task.CompletedTask;
return base.InitializeAsync();
}
}
8 changes: 7 additions & 1 deletion src/NuSocial.Core/ViewModels/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public LoginViewModel(IDialogService dialogService,
IConfiguration configuration,
IDatabase db) : base(dialogService, navigationService)
{
Title = L["Login"];

_configuration = configuration;
_db = db;
}
Expand Down Expand Up @@ -80,8 +80,14 @@ private Task LoginAsync()
});
}

public override Task InitializeAsync()
{
Title = L["Login"];
return base.InitializeAsync();
}
public override Task OnFirstAppear()
{

SetWhenDebug();
return Task.CompletedTask;
}
Expand Down
9 changes: 8 additions & 1 deletion src/NuSocial.Core/ViewModels/RegisterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public RegisterViewModel(IDialogService dialogService,
IDatabase db)
: base(dialogService, navigationService)
{
Title = L["CreateAccount"];

_db = db;
}

Expand All @@ -37,12 +37,19 @@ public RegisterViewModel(IDialogService dialogService,

public override Task OnFirstAppear()
{

GenerateKeyPair();

WeakReferenceMessenger.Default.Send<ResetNavMessage>(new("//start"));
return Task.CompletedTask;
}

public override Task InitializeAsync()
{
Title = L["CreateAccount"];
return base.InitializeAsync();
}

private void GenerateKeyPair()
{
var keyPair = NostrKeyPair.GenerateNew();
Expand Down
4 changes: 3 additions & 1 deletion src/NuSocial.Core/ViewModels/RelaysViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public RelaysViewModel(IDialogService dialogService,
IDatabase db)
: base(dialogService, navigationService)
{
Title = L["Relays"];

_db = db;
}

public override async Task InitializeAsync()
{
Title = L["Relays"];

// We need to cancel any work currently handling nostr information, so fire that message.
WeakReferenceMessenger.Default.Send<NostrStateChangeMessage>(new(false));

Expand Down
17 changes: 14 additions & 3 deletions src/NuSocial.Core/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Messaging;
using NuSocial.Core.ViewModel;
using NuSocial.Localization;
using NuSocial.Messages;
using Volo.Abp.DependencyInjection;

Expand All @@ -24,7 +25,7 @@ public partial class ShellViewModel : BaseViewModel, ISingletonDependency

private IRedirectService? _redirectService;

public ShellViewModel(IAppInfo appInfo)
public ShellViewModel(IAppInfo appInfo, LocalizationResourceManager localizationManager)
{
if (appInfo is null)
{
Expand All @@ -42,10 +43,20 @@ public ShellViewModel(IAppInfo appInfo)
{
RefreshMenuItems(false);
});

localizationManager.PropertyChanged += (_, _) =>
{
UpdateProperties();
};
}

private void UpdateProperties()
{
throw new NotImplementedException();
}

public ShellViewModel()
: this(AppInfo.Current)
public ShellViewModel(LocalizationResourceManager localizationManager)
: this(AppInfo.Current, localizationManager)
{
}

Expand Down
6 changes: 6 additions & 0 deletions src/NuSocial.Core/ViewModels/StartViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ namespace NuSocial.ViewModels;
public partial class StartViewModel : BaseViewModel, ITransientDependency
{
public StartViewModel(IDialogService dialogService, INavigationService navigationService) : base(dialogService, navigationService)
{

}

public override Task InitializeAsync()
{
Title = L["NuSocial"];
return base.InitializeAsync();
}

[RelayCommand(CanExecute = nameof(IsNotBusy))]
Expand Down
Loading

0 comments on commit b2b4453

Please sign in to comment.