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

Add ITranslationProvider.LoadTranslationsAsync() #15886

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
GetAllStringsFromCultureHierarchyAsync() return IAsyncEnumerable<Loca…
…lizedString>
  • Loading branch information
hishamco committed May 3, 2024
commit 47050eb71ca43f95786b174a41d15516aa52c35a
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ public virtual LocalizedString this[string name]
public virtual IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
{
var culture = CultureInfo.CurrentUICulture;
var localizedStrings = includeParentCultures
? GetAllStringsFromCultureHierarchyAsync(culture)
: GetAllStringsAsync(culture);

return includeParentCultures
? GetAllStringsFromCultureHierarchyAsync(culture).GetAwaiter().GetResult()
: GetAllStringsAsync(culture).ToEnumerable();
return localizedStrings.ToEnumerable();
}

/// <inheritdocs />
Expand Down Expand Up @@ -120,10 +121,10 @@ private async IAsyncEnumerable<LocalizedString> GetAllStringsAsync(CultureInfo c
}
}

private async Task<List<LocalizedString>> GetAllStringsFromCultureHierarchyAsync(CultureInfo culture)
private async IAsyncEnumerable<LocalizedString> GetAllStringsFromCultureHierarchyAsync(CultureInfo culture)
{
var currentCulture = culture;
var allLocalizedStrings = new List<LocalizedString>();
var resourcesNames = new HashSet<string>();

do
{
Expand All @@ -133,17 +134,17 @@ private async Task<List<LocalizedString>> GetAllStringsFromCultureHierarchyAsync
{
foreach (var localizedString in localizedStrings)
{
if (!allLocalizedStrings.Any(ls => ls.Name == localizedString.Name))
if (!resourcesNames.Contains(localizedString.Name))
{
allLocalizedStrings.Add(localizedString);
resourcesNames.Add(localizedString.Name);

yield return localizedString;
}
}
}

currentCulture = currentCulture.Parent;
} while (currentCulture != currentCulture.Parent);

return allLocalizedStrings;
}

[Obsolete("This method is deprecated, please use GetTranslationAsync instead.")]
Expand Down