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

Wildcard locales as fallback #254

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Using static language-country pairings derived from the locale and searching for `locale={locale}-*` only as fallback

## [3.13.3] - 2023-11-16

### Removed

- Prefix wildcard to query for locale at Master Data's ProductReviews

## [3.13.2] - 2023-08-09

### Added

- Translation of the ShowMore component.

## [3.13.1] - 2023-06-13
Expand Down
21 changes: 14 additions & 7 deletions dotnet/Services/ProductReviewService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Net;
using ReviewsRatings.DataSources;
using Vtex.Api.Context;
using ReviewsRatings.Utils;

/// <summary>
/// Business logic
Expand Down Expand Up @@ -235,7 +236,7 @@
return reviews;
}

public async Task<IList<Review>> LimitReviews(IList<Review> reviews, int from, int to)

Check warning on line 239 in dotnet/Services/ProductReviewService.cs

View workflow job for this annotation

GitHub Actions / QE / Lint .Net

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
int take = maximumReturnedRecords;
if (to > 0)
Expand All @@ -248,7 +249,7 @@
return reviews;
}

public async Task<IList<Review>> FilterReviews(IList<Review> reviews, string searchTerm, string orderBy, string status)

Check warning on line 252 in dotnet/Services/ProductReviewService.cs

View workflow job for this annotation

GitHub Actions / QE / Lint .Net

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
if (reviews != null && reviews.Count > 0)
{
Expand Down Expand Up @@ -393,7 +394,7 @@
{
string searchQuery = string.Empty;
string ratingQuery = string.Empty;
string localeQuery = string.Empty;
string localeQuery = $"(locale={locale}-*)";
bool ratingFilter = rating > 0 && rating <= 5;
bool pastRevNLocale = pastReviews && !string.IsNullOrEmpty(locale);
ReviewsResponseWrapper wrapper = new ReviewsResponseWrapper();
Expand All @@ -413,13 +414,23 @@

AppSettings settings = await GetAppSettings();

if (pastRevNLocale)
if (!string.IsNullOrEmpty(locale) && Locale.localeList.ContainsKey(locale))
{
localeQuery = "";
foreach (var language in Locale.localeList[locale])
{
localeQuery += $"(locale={locale}-{language}) OR";
}
localeQuery = localeQuery.Substring(localeQuery.Length - 2);
}

if (pastRevNLocale)
{
if (settings.RequireApproval)
{
searchQuery = $" AND approved=true";
}
localeQuery = $"((locale={locale}-*) OR (locale is null))";
localeQuery = $"({localeQuery} OR (locale is null))";
if (ratingFilter)
{
ratingQuery = $" AND rating={rating}";
Expand All @@ -438,10 +449,6 @@
{
searchQuery = $"{searchQuery}&approved=true";
}
if (!string.IsNullOrEmpty(locale))
{
localeQuery = $"&locale={locale}-*";
}

wrapper = await this._productReviewRepository.GetProductReviewsMD($"productId={productId}{sort}{searchQuery}{ratingQuery}{localeQuery}", from.ToString(), to.ToString());
}
Expand Down Expand Up @@ -701,7 +708,7 @@
return await _productReviewRepository.SuccessfulMigration();
}

private async Task<Review> ConvertLegacyReview(LegacyReview review)

Check warning on line 711 in dotnet/Services/ProductReviewService.cs

View workflow job for this annotation

GitHub Actions / QE / Lint .Net

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Review newReview = new Review
{
Expand Down Expand Up @@ -845,7 +852,7 @@
return retval;
}

private async Task<string> GetSortQuery(string orderBy)

Check warning on line 855 in dotnet/Services/ProductReviewService.cs

View workflow job for this annotation

GitHub Actions / QE / Lint .Net

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
string sort = string.Empty;
if (!string.IsNullOrEmpty(orderBy))
Expand Down
139 changes: 139 additions & 0 deletions dotnet/Utils/Locale.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using System.Collections.Generic;

namespace ReviewsRatings.Utils
{
public static class Locale
{
public static Dictionary<string, List<string>> localeList = new Dictionary<string, List<string>>() {

{ "ca", new List<string>() {"ES", "AD" }},
{ "ar", new List<string>() {"JO", "KM", "ER", "OM", "EG", "PS", "SY", "DJ", "SA", "SO", "SD", "YE", "LY", "TN", "EH", "MA", "BH", "AE", "KW", "LB", "QA", "IQ", "TD", "MR", "DZ"}},
{ "fa", new List<string>() {"AF", "IR"}},
{ "ps", new List<string>() { "AF"}},
{ "en", new List<string>() { "PH", "SH", "IM", "LC", "DM", "GY", "NA", "WS", "AS", "IN", "PW", "GM", "FM", "TO", "SG", "SZ", "AI", "IE", "NU", "MW", "FJ", "CX", "NZ", "BB", "SL", "JE", "TK", "PR", "RW", "HK", "PG", "GI", "LS", "SD", "BZ", "KR", "VG", "SB", "MT", "ZA", "VC", "CK", "BW", "NR", "CM", "UG", "MS", "AQ", "HM", "ER", "GG", "LR", "AU", "ZM", "MU", "GB", "IO", "US", "VU", "CC", "TT", "GD", "KI", "UM", "VI", "ZW", "CA", "MH", "GU", "KE", "TC", "PN", "NF", "BM", "BS", "TV", "SC", "KY", "PK", "KN", "SX", "AG", "SS", "GH", "FK", "NG", "TZ", "GS", "JM", "CW", "MP"}},
{ "sq", new List<string>() { "AL", "ME"}},
{ "hy", new List<string>() { "AM"}},
{ "pt", new List<string>() { "ST", "CV", "TL", "GQ", "BR", "MO", "GW", "MZ", "AO", "PT"}},
{ "es", new List<string>() { "MX", "PY", "AQ", "ES", "CO", "DO", "PE", "PA", "PR", "HN", "CU", "BO", "CL", "UY", "GT", "NI", "EH", "VE", "SV", "GQ", "EC", "AR", "CR"}},
{ "fr", new List<string>() { "NC", "CH", "RE", "LU", "PM", "CG", "AQ", "GF", "IT", "KM", "BL", "GN", "BI", "TF", "BJ", "NE", "DJ", "CD", "RW", "MC", "MU", "SC", "WF", "GA", "PF", "BF", "CI", "HT", "MG", "SN", "CF", "TN", "VU", "ML", "EH", "YT", "FR", "GP", "MA", "BE", "GQ", "LB", "MQ", "MF", "CA", "TD", "TG", "MR", "CM"}},
{ "ru", new List<string>() { "MD", "TJ", "KG", "RU", "AQ", "BY", "KZ"}},
{ "sm", new List<string>() { "AS", "WS", "TK"}},
{ "de", new List<string>() { "DE", "CH", "LU", "BE", "IT", "AT", "NA", "LI"}},
{ "nl", new List<string>() { "AW", "BE", "NL", "CW", "SR", "BQ", "SX"}},
{ "pap", new List<string>() { "AW"}},
{ "sv", new List<string>() { "FI", "AX", "SE"}},
{ "az", new List<string>() { "AZ"}},
{ "bs", new List<string>() { "BA", "ME"}},
{ "hr", new List<string>() { "BA", "HR", "ME"}},
{ "sr", new List<string>() { "RS", "BA", "ME"}},
{ "bn", new List<string>() { "BD"}},
{ "bg", new List<string>() { "BG"}},
{ "ms", new List<string>() { "MY", "BN", "SG"}},
{ "qu", new List<string>() { "BO"}},
{ "gn", new List<string>() { "BO", "PY"}},
{ "ay", new List<string>() { "BO"}},
{ "dz", new List<string>() { "BT"}},
{ "no", new List<string>() { "SJ", "BV", "NO"}},
{ "tn", new List<string>() { "ZA", "BW"}},
{ "be", new List<string>() { "BY"}},
{ "sg", new List<string>() { "CF"}},
{ "it", new List<string>() { "SM", "CH", "VA", "IT"}},
{ "rm", new List<string>() { "CH"}},
{ "rar", new List<string>() { "CK"}},
{ "zh-hans", new List<string>() { "CN", "SG"}},
{ "el", new List<string>() { "GR", "CY"}},
{ "tr", new List<string>() { "TR", "CY"}},
{ "cs", new List<string>() { "CZ"}},
{ "so", new List<string>() { "SO", "DJ"}},
{ "aa", new List<string>() { "DJ"}},
{ "da", new List<string>() { "DK", "FO", "GL"}},
{ "et", new List<string>() { "EE"}},
{ "ti", new List<string>() { "ER"}},
{ "ast", new List<string>() { "ES"}},
{ "eu", new List<string>() { "ES"}},
{ "gl", new List<string>() { "ES"}},
{ "am", new List<string>() { "ET"}},
{ "om", new List<string>() { "ET"}},
{ "fi", new List<string>() { "FI"}},
{ "se", new List<string>() { "FI", "NO"}},
{ "fo", new List<string>() { "FO"}},
{ "ga", new List<string>() { "IE", "GB"}},
{ "cy", new List<string>() { "GB"}},
{ "gd", new List<string>() { "GB"}},
{ "kw", new List<string>() { "GB"}},
{ "ka", new List<string>() { "GE"}},
{ "kl", new List<string>() { "GL"}},
{ "ch", new List<string>() { "MP", "GU"}},
{ "zh-hant", new List<string>() { "MO", "TW", "HK"}},
{ "ht", new List<string>() { "HT"}},
{ "hu", new List<string>() { "HU"}},
{ "id", new List<string>() { "ID"}},
{ "he", new List<string>() { "PS", "IL"}},
{ "hi", new List<string>() { "IN"}},
{ "ku", new List<string>() { "IQ"}},
{ "is", new List<string>() { "IS"}},
{ "ja", new List<string>() { "JP", "PW"}},
{ "sw", new List<string>() { "TZ", "KE", "UG", "KM"}},
{ "ky", new List<string>() { "KG"}},
{ "km", new List<string>() { "KH"}},
{ "ko", new List<string>() { "KR", "KP"}},
{ "kk", new List<string>() { "KZ"}},
{ "lo", new List<string>() { "LA"}},
{ "si", new List<string>() { "LK"}},
{ "ta", new List<string>() { "LK", "SG"}},
{ "st", new List<string>() { "LS", "ZA"}},
{ "lt", new List<string>() { "LT"}},
{ "lb", new List<string>() { "LU"}},
{"lv", new List<string>() { "LV"}},
{ "zgh", new List<string>() { "MA"}},
{ "ro", new List<string>() { "MD", "RO"}},
{ "uk", new List<string>() { "MD", "UA"}},
{ "srp", new List<string>() { "ME"}},
{ "mg", new List<string>() { "MG"}},
{ "mh", new List<string>() { "MH"}},
{ "mk", new List<string>() { "MK"}},
{ "my", new List<string>() { "MM"}},
{ "mn", new List<string>() { "MN"}},
{ "mt", new List<string>() { "MT"}},
{ "mfe", new List<string>() { "MU"}},
{ "dv", new List<string>() { "MV"}},
{ "ny", new List<string>() { "MW"}},
{ "sf", new List<string>() { "NA"}},
{ "pih", new List<string>() { "NF", "PN"}},
{ "nb", new List<string>() { "NO"}},
{ "nn", new List<string>() { "NO"}},
{ "ne", new List<string>() { "NP"}},
{ "na", new List<string>() { "NR"}},
{ "niu", new List<string>() { "NU"}},
{ "mi", new List<string>() { "NZ"}},
{ "tpi", new List<string>() { "PG"}},
{ "ho", new List<string>() { "PG"}},
{ "tl", new List<string>() { "PH"}},
{ "ur", new List<string>() { "PK"}},
{ "pl", new List<string>() { "PL"}},
{ "pau", new List<string>() { "PW"}},
{ "sov", new List<string>() { "PW"}},
{ "tox", new List<string>() { "PW"}},
{ "sr-Latn", new List<string>() { "RS"}},
{ "rw", new List<string>() { "RW"}},
{ "crs", new List<string>() { "SC"}},
{ "sl", new List<string>() { "SI"}},
{ "sk", new List<string>() { "SK"}},
{ "ss", new List<string>() { "SZ"}},
{ "th", new List<string>() { "TH"}},
{ "tg", new List<string>() { "TJ"}},
{ "tkl", new List<string>() { "TK"}},
{ "tet", new List<string>() { "TL"}},
{ "tk", new List<string>() { "TM"}},
{ "uz", new List<string>() { "UZ"}},
{ "kaa", new List<string>() { "UZ"}},
{ "vi", new List<string>() { "VN"}},
{ "bi", new List<string>() { "VU"}},
{ "af", new List<string>() { "ZA"}},
{ "xh", new List<string>() { "ZA"}},
{ "zu", new List<string>() { "ZA"}},
{ "sn", new List<string>() { "ZW"}},
{ "nd", new List<string>() { "ZW"}}
};
}
}
Loading