Skip to content
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

修复在当前 LocalizationValues 无法取值时,从 fallback 取值失败的问题。 #7

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ public class LocalizationValues(ILocalizedValues? fallback) : ILocalizedValues
public string IetfLanguageTag => "default";

/// <inheritdoc />
public string this[string key] => _strings[key] ?? fallback![key];
public string this[string key]
{
get
{
if (_strings.TryGetValue(key,out var value) && value != null)
{
return value;
}
if (fallback != null)
{
return fallback[key];
}
return "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这么长的语句,可以用更长的 null 传播表达式?

}
}

private readonly FrozenDictionary<string, string> _strings = new Dictionary<string, string>
{
Expand Down