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

implement custom localization #1784

Merged
merged 3 commits into from
Feb 29, 2024
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
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 @@ -75,6 +75,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 @@ -130,6 +134,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 @@ -168,4 +220,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
Loading