-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add - doc - Implemented preferred cultures
--- Just like how we've implemented preferred user language, we've also implemented preferred cultures. --- Type: add Breaking: False Doc Required: True Backport Required: False Part: 1/1
- Loading branch information
Showing
16 changed files
with
218 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
public/Nitrocid/Shell/Shells/Admin/Commands/UserCulture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// Nitrocid KS Copyright (C) 2018-2025 Aptivi | ||
// | ||
// This file is part of Nitrocid KS | ||
// | ||
// Nitrocid KS is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Nitrocid KS is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
using Terminaux.Writer.ConsoleWriters; | ||
using Nitrocid.Kernel.Exceptions; | ||
using Nitrocid.Languages; | ||
using Nitrocid.Shell.ShellBase.Commands; | ||
using Nitrocid.Users; | ||
using System.Globalization; | ||
|
||
namespace Nitrocid.Shell.Shells.Admin.Commands | ||
{ | ||
class UserCultureCommand : BaseCommand, ICommand | ||
{ | ||
|
||
public override int Execute(CommandParameters parameters, ref string variableValue) | ||
{ | ||
string userName = parameters.ArgumentsList[0]; | ||
string culture = parameters.ArgumentsList[1]; | ||
int userIndex = UserManagement.GetUserIndex(userName); | ||
if (culture == "clear") | ||
{ | ||
// If we're doing this on ourselves, change the kernel culture to the system culture | ||
culture = CultureManager.currentCulture.Name; | ||
if (UserManagement.CurrentUser.Username == userName) | ||
{ | ||
CultureManager.currentUserCulture = CultureManager.currentCulture; | ||
UserManagement.CurrentUser.PreferredCulture = culture; | ||
} | ||
|
||
// Now, change the culture in the user config | ||
UserManagement.Users[userIndex].PreferredCulture = null; | ||
UserManagement.SaveUsers(); | ||
TextWriterColor.Write(Translate.DoTranslation("Preferred user culture set to {0}. You may want to log in again."), culture); | ||
} | ||
else if (CultureManager.GetCulturesDictionary().TryGetValue(culture, out CultureInfo? cultureInfo)) | ||
{ | ||
// Do it locally | ||
if (UserManagement.CurrentUser.Username == userName) | ||
{ | ||
CultureManager.currentUserCulture = cultureInfo; | ||
UserManagement.CurrentUser.PreferredCulture = culture; | ||
} | ||
|
||
// Now, change the culture in the user config | ||
UserManagement.Users[userIndex].PreferredCulture = culture; | ||
UserManagement.SaveUsers(); | ||
TextWriterColor.Write(Translate.DoTranslation("Preferred user culture set to {0}. You may want to log in again."), culture); | ||
} | ||
else | ||
{ | ||
TextWriterColor.Write(Translate.DoTranslation("Invalid culture") + " {0}", culture); | ||
return KernelExceptionTools.GetErrorCode(KernelExceptionType.NoSuchCulture); | ||
} | ||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// Nitrocid KS Copyright (C) 2018-2025 Aptivi | ||
// | ||
// This file is part of Nitrocid KS | ||
// | ||
// Nitrocid KS is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Nitrocid KS is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
using Nitrocid.ConsoleBase.Colors; | ||
using Nitrocid.ConsoleBase.Writers; | ||
using Terminaux.Writer.ConsoleWriters; | ||
using Nitrocid.Kernel.Exceptions; | ||
using Nitrocid.Shell.ShellBase.Commands; | ||
using Nitrocid.Shell.ShellBase.Switches; | ||
using Nitrocid.Users; | ||
using Terminaux.Inputs.Styles.Choice; | ||
using System.Linq; | ||
using Terminaux.Inputs.Styles; | ||
using Nitrocid.Languages; | ||
|
||
namespace Nitrocid.Shell.Shells.UESH.Commands | ||
{ | ||
/// <summary> | ||
/// Changes your kernel culture | ||
/// </summary> | ||
/// <remarks> | ||
/// If you want to change your kernel culture without having to go to Settings (for scripting purposes), you can use this command. | ||
/// <br></br> | ||
/// The user must have at least the administrative privileges before they can run the command. | ||
/// </remarks> | ||
class ChCultureCommand : BaseCommand, ICommand | ||
{ | ||
|
||
public override int Execute(CommandParameters parameters, ref string variableValue) | ||
{ | ||
bool useUser = SwitchManager.ContainsSwitch(parameters.SwitchesList, "-user"); | ||
|
||
// Culture selection takes only one culture | ||
string culture = parameters.ArgumentsList[0]; | ||
var cultures = CultureManager.GetCultureCodes(); | ||
if (!cultures.Contains(culture)) | ||
{ | ||
TextWriters.Write(Translate.DoTranslation("Invalid culture") + $" {culture}", true, KernelColorType.Error); | ||
return KernelExceptionTools.GetErrorCode(KernelExceptionType.NoSuchLanguage); | ||
} | ||
|
||
// Change the culture | ||
if (useUser) | ||
{ | ||
UserManagement.CurrentUser.PreferredCulture = culture; | ||
UserManagement.SaveUsers(); | ||
} | ||
else | ||
CultureManager.UpdateCulture(culture); | ||
TextWriterColor.Write(Translate.DoTranslation("You may need to log out and log back in for changes to take effect.")); | ||
return 0; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.