Skip to content

Commit

Permalink
implement custom localization (#1784)
Browse files Browse the repository at this point in the history
* implement custom localization

* move the locale settings next to the timezone

* align form-select font-size to form-control
  • Loading branch information
Masterjun3 authored Feb 29, 2024
1 parent c0d9d21 commit 80ee0e4
Show file tree
Hide file tree
Showing 12 changed files with 3,865 additions and 7 deletions.
2 changes: 2 additions & 0 deletions TASVideos.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static class CacheKeys
public const string AwardsCache = "AwardsCache";
public const string UnreadMessageCount = "UnreadMessageCountCache-";
public const string MovieTokens = "MovieTokenData";
public const string UsersWithCustomLocale = "UsersWithCustomLocale";
public const string CustomUserLocalePrefix = "CustomUserLocale-";
}

// These perform site functions, maybe they should be in the database?
Expand Down
6 changes: 6 additions & 0 deletions TASVideos.Core/Services/UserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,10 @@ public bool IsPasswordAllowed(string? userName, string? email, string? password)

return true;
}

public void ClearCustomLocaleCache(int userId)
{
_cache.Remove(CacheKeys.UsersWithCustomLocale);
_cache.Remove(CacheKeys.CustomUserLocalePrefix + userId);
}
}
57 changes: 57 additions & 0 deletions TASVideos.Data/Entity/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public class User : IdentityUser<int>, ITrackable

public UserPreference? AutoWatchTopic { get; set; }

public UserDateFormat DateFormat { get; set; } = UserDateFormat.Auto;
public UserTimeFormat TimeFormat { get; set; } = UserTimeFormat.Auto;
public UserDecimalFormat DecimalFormat { get; set; } = UserDecimalFormat.Auto;

public virtual ICollection<UserRole> UserRoles { get; set; } = new HashSet<UserRole>();
public virtual ICollection<SubmissionAuthor> Submissions { get; set; } = new HashSet<SubmissionAuthor>();
public virtual ICollection<PublicationAuthor> Publications { get; set; } = new HashSet<PublicationAuthor>();
Expand Down Expand Up @@ -129,6 +133,54 @@ public enum PreferredPronounTypes
Other
}

public enum UserDateFormat
{
[Display(Name = "Automatic")]
Auto = 0,

[Display(Name = "yyyy-MM-dd (2024-02-29)")]
YMMDD,

[Display(Name = "dd/MM/yyyy (29/02/2024)")]
DDMMY,

[Display(Name = "dd.MM.yyyy (29.02.2024)")]
DDMMYDot,

[Display(Name = "d/M/yyyy (29/2/2024)")]
DMY,

[Display(Name = "MM/dd/yyyy (02/29/2024)")]
MMDDY,

[Display(Name = "M/d/yyyy (2/29/2024)")]
MDY,
}

public enum UserTimeFormat
{
[Display(Name = "Automatic")]
Auto = 0,

[Display(Name = "24-hour clock (17:35)")]
Clock24Hour,

[Display(Name = "12-hour clock (5:35 PM)")]
Clock12Hour
}

public enum UserDecimalFormat
{
[Display(Name = "Automatic")]
Auto = 0,

[Display(Name = "Dot (1.23)")]
Dot,

[Display(Name = "Comma (1,23)")]
Comma
}

public static class UserExtensions
{
public static async Task<bool> Exists(this IQueryable<User> query, string userName)
Expand Down Expand Up @@ -167,4 +219,9 @@ public static IQueryable<User> ForUsers(this IQueryable<User> query, IEnumerable
{
return query.Where(u => users.Contains(u.UserName));
}

public static IQueryable<User> ThatHaveCustomLocale(this IQueryable<User> query)
{
return query.Where(u => u.DateFormat != UserDateFormat.Auto || u.TimeFormat != UserTimeFormat.Auto || u.DecimalFormat != UserDecimalFormat.Auto);
}
}
Loading

0 comments on commit 80ee0e4

Please sign in to comment.