-
Notifications
You must be signed in to change notification settings - Fork 462
Fixes for LocalizedString issues #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c46cc43
d0c37a6
4a7380d
e79e788
9b123f3
e82dcec
d0e30ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,7 +217,7 @@ protected async Task TrySendStartMessageAsync(Player player, LocalizedString map | |
| return; | ||
| } | ||
|
|
||
| var message = (configuration.Message?.ToString() ?? PlugInResources.BaseInvasionPlugIn_DefaultStartMessage).Replace("{mapName}", mapName.GetTranslation(player.Culture), StringComparison.InvariantCulture); | ||
| var message = (configuration.Message.GetTranslation(player.Culture) ?? PlugInResources.BaseInvasionPlugIn_DefaultStartMessage).Replace("{mapName}", mapName.GetTranslation(player.Culture), StringComparison.InvariantCulture); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The call to var message = (configuration.Message.GetTranslation(player.Culture) ?? PlugInResources.BaseInvasionPlugIn_DefaultStartMessage).Replace("{mapName}", mapName.GetTranslation(player.Culture) ?? string.Empty, StringComparison.InvariantCulture); |
||
|
|
||
| if (this.IsPlayerOnMap(player)) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,7 +139,7 @@ | |
| /// </returns> | ||
| public override string? ToString() | ||
| { | ||
| return this.GetTranslation(CultureInfo.CurrentCulture); | ||
| return this.Value is null ? null : this.GetTranslation(CultureInfo.CurrentCulture); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -155,10 +155,12 @@ | |
| /// <paramref name="fallbackToNeutral"/> is <see langword="true"/> and no specific translation exists, | ||
| /// or an empty string if neither is available. | ||
| /// </returns> | ||
| public string GetTranslation(CultureInfo cultureInfo, bool fallbackToNeutral = true) | ||
| public string? GetTranslation(CultureInfo cultureInfo, bool fallbackToNeutral = true) | ||
| { | ||
| var span = this.GetTranslationAsSpan(cultureInfo, fallbackToNeutral); | ||
| return new(span); | ||
| return span.IsEmpty | ||
| ? null | ||
| : new(span); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -236,7 +238,7 @@ | |
| // i. If text is null or empty: remove that section (and possible trailing/leading separators). | ||
| // ii. Else: replace its content with text. | ||
| // - If not found and text is not null/empty: append "||xx=text". | ||
| // 4. Return new LocalizedString with computed value. | ||
|
Check warning on line 241 in src/Interfaces/LocalizedString.cs
|
||
|
|
||
| var languageCode = cultureInfo.TwoLetterISOLanguageName; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // <copyright file="EntityDataContextFactory.cs" company="MUnique"> | ||
| // Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
| // </copyright> | ||
|
|
||
| namespace MUnique.OpenMU.Persistence.EntityFramework; | ||
|
|
||
| using Microsoft.EntityFrameworkCore.Design; | ||
|
|
||
| /// <summary> | ||
| /// Design-time factory for <see cref="EntityDataContext"/>. | ||
| /// </summary> | ||
| public class EntityDataContextFactory : IDesignTimeDbContextFactory<EntityDataContext> | ||
| { | ||
| /// <inheritdoc /> | ||
| public EntityDataContext CreateDbContext(string[] args) | ||
| { | ||
| if (!ConnectionConfigurator.IsInitialized) | ||
| { | ||
| ConnectionConfigurator.Initialize(new ConfigFileDatabaseConnectionStringProvider()); | ||
| } | ||
|
|
||
| return new EntityDataContext(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling
string.Formatwith an emptyargsarray will throw aFormatExceptionif thetranslationstring contains any format specifiers (e.g.,{0}). Some call sites ofShowGoldenMessageAsyncpass an emptyargsarray. To make this more robust, you could check ifargshas any elements before callingstring.Format.