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 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Revert "Use IAsyncEnumerable"
This reverts commit 93a802e.
  • Loading branch information
hishamco committed Apr 26, 2024
commit 3035a04037ffabed0e522f374a731b645eea1a56
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 71,9 @@ public virtual IEnumerable<LocalizedString> GetAllStrings(bool includeParentCult
{
var culture = CultureInfo.CurrentUICulture;

var localizedStrings = includeParentCultures
? GetAllStringsFromCultureHierarchyAsync(culture)
: GetAllStringsAsync(culture);

return localizedStrings.ToEnumerable();
return includeParentCultures
? GetAllStringsFromCultureHierarchyAsync(culture).GetAwaiter().GetResult()
: GetAllStringsAsync(culture).ToEnumerable();
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider maintaining asynchronous flow in GetAllStrings.

- return includeParentCultures
-     ? GetAllStringsFromCultureHierarchyAsync(culture).GetAwaiter().GetResult()
-     : GetAllStringsAsync(culture).ToEnumerable();
  return includeParentCultures
      ? await GetAllStringsFromCultureHierarchyAsync(culture).ToListAsync()
      : await GetAllStringsAsync(culture).ToListAsync();

This change avoids potential performance bottlenecks by not blocking the thread while converting IAsyncEnumerable to IEnumerable.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return includeParentCultures
? GetAllStringsFromCultureHierarchyAsync(culture).GetAwaiter().GetResult()
: GetAllStringsAsync(culture).ToEnumerable();
return includeParentCultures
? await GetAllStringsFromCultureHierarchyAsync(culture).ToListAsync()
: await GetAllStringsAsync(culture).ToListAsync();

}

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

private async IAsyncEnumerable<LocalizedString> GetAllStringsFromCultureHierarchyAsync(CultureInfo culture)
private async Task<List<LocalizedString>> GetAllStringsFromCultureHierarchyAsync(CultureInfo culture)
{
var currentCulture = culture;
var allLocalizedStrings = new List<LocalizedString>();
Expand All @@ -137,13 135,15 @@ private async IAsyncEnumerable<LocalizedString> GetAllStringsFromCultureHierarch
{
if (!allLocalizedStrings.Any(ls => ls.Name == localizedString.Name))
{
yield return localizedString;
allLocalizedStrings.Add(localizedString);
}
}
}

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

return allLocalizedStrings;
}

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