From ad39d71cd4d68c1697aca804710fc809ba82c2eb Mon Sep 17 00:00:00 2001 From: Gorniaky Date: Wed, 3 Jun 2026 13:42:24 -0300 Subject: [PATCH 1/3] feat: refactor locale handling and improve user locale command --- lib/cli/context.dart | 4 +++- lib/cli/locale.dart | 7 +++++++ lib/cli/paths.dart | 8 ++++---- lib/commands/user/locale.dart | 17 ++++++----------- 4 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 lib/cli/locale.dart diff --git a/lib/cli/context.dart b/lib/cli/context.dart index 1d1b068..f0d5705 100644 --- a/lib/cli/context.dart +++ b/lib/cli/context.dart @@ -8,10 +8,12 @@ import "package:discloud/cli/spin/cli_spin.dart"; import "package:discloud/extensions/duration.dart"; import "package:discloud/extensions/list.dart"; import "package:discloud/services/discloud/api_client.dart"; +import "package:intl/intl.dart"; import "package:local_store/local_store.dart"; import "package:path/path.dart"; import "package:tint/tint.dart"; +part "locale.dart"; part "paths.dart"; class CliContext implements Disposable { @@ -64,7 +66,7 @@ class CliContext implements Disposable { final LocalStore store; final IPrinter printer; - String get locale => Platform.localeName; + String get locale => _localeName; Directory get workspaceFolder => _workspaceFolder; diff --git a/lib/cli/locale.dart b/lib/cli/locale.dart new file mode 100644 index 0000000..4afe176 --- /dev/null +++ b/lib/cli/locale.dart @@ -0,0 +1,7 @@ +part of "context.dart"; + +const String _localePattern = r"^\w{2}[-_]\w{2}$"; +final RegExp _localeRegexp = .new(_localePattern); +final String _localeName = + _localeRegexp.firstMatch(Platform.localeName)?.input ?? + Intl.getCurrentLocale(); diff --git a/lib/cli/paths.dart b/lib/cli/paths.dart index 9e4143a..4eda34c 100644 --- a/lib/cli/paths.dart +++ b/lib/cli/paths.dart @@ -2,9 +2,9 @@ part of "context.dart"; final Directory _workspaceFolder = .current; -final _rootFilePath = Platform.resolvedExecutable; +final String _rootFilePath = Platform.resolvedExecutable; -final _rootPath = dirname(_rootFilePath); +final String _rootPath = dirname(_rootFilePath); final String _userHomePath = Platform.environment[const ["HOME", "USERPROFILE"].firstWhere( @@ -14,6 +14,6 @@ final String _userHomePath = }, )]!; -final _cliConfigDir = joinAll([_userHomePath, ".discloud"]); +final String _cliConfigDir = joinAll([_userHomePath, ".discloud"]); -final _cliConfigFilePath = joinAll([_cliConfigDir, ".cli"]); +final String _cliConfigFilePath = joinAll([_cliConfigDir, ".cli"]); diff --git a/lib/commands/user/locale.dart b/lib/commands/user/locale.dart index e662c0e..8f0806c 100644 --- a/lib/commands/user/locale.dart +++ b/lib/commands/user/locale.dart @@ -1,22 +1,15 @@ -import "dart:io"; - import "package:args/command_runner.dart"; import "package:discloud/extensions/command.dart"; import "package:discloud/utils/messages.dart"; final class UserLocaleCommand extends Command { - static const _localePattern = r"^\w{2}[-_]\w{2}$"; - static final _localeRegexp = RegExp(_localePattern); - static final _localeName = - _localeRegexp.firstMatch(Platform.localeName)?.input ?? "en-US"; - UserLocaleCommand() { argParser - ..addOption("locale", abbr: "l", valueHelp: _localeName) + ..addOption("locale", abbr: "l", valueHelp: context.locale) ..addFlag( "system", abbr: "s", - help: "Use current system language ($_localeName)", + help: "Use current system language (${context.locale})", negatable: false, ); } @@ -31,9 +24,11 @@ final class UserLocaleCommand extends Command { Future run() async { final system = argResults!.flag("system"); - final locale = system ? Platform.localeName : argResults!.option("locale"); + final locale = system ? context.locale : argResults!.option("locale"); - final spinner = context.printer.spin(text: "Defining locale..."); + final spinner = context.printer.spin( + text: "Defining the user's locale to $locale...", + ); final response = await context.api.put("/locale/$locale"); From fd18f77d194458e1c467a0534f5cebc2128d871b Mon Sep 17 00:00:00 2001 From: Gorniaky Date: Wed, 3 Jun 2026 13:45:16 -0300 Subject: [PATCH 2/3] refactor: update locale handling to use localeName variable --- lib/cli/context.dart | 2 +- lib/cli/locale.dart | 3 ++- lib/commands/user/locale.dart | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/cli/context.dart b/lib/cli/context.dart index f0d5705..b8cbcfe 100644 --- a/lib/cli/context.dart +++ b/lib/cli/context.dart @@ -66,7 +66,7 @@ class CliContext implements Disposable { final LocalStore store; final IPrinter printer; - String get locale => _localeName; + String get locale => localeName; Directory get workspaceFolder => _workspaceFolder; diff --git a/lib/cli/locale.dart b/lib/cli/locale.dart index 4afe176..0511f89 100644 --- a/lib/cli/locale.dart +++ b/lib/cli/locale.dart @@ -2,6 +2,7 @@ part of "context.dart"; const String _localePattern = r"^\w{2}[-_]\w{2}$"; final RegExp _localeRegexp = .new(_localePattern); -final String _localeName = + +final String localeName = _localeRegexp.firstMatch(Platform.localeName)?.input ?? Intl.getCurrentLocale(); diff --git a/lib/commands/user/locale.dart b/lib/commands/user/locale.dart index 8f0806c..3d16688 100644 --- a/lib/commands/user/locale.dart +++ b/lib/commands/user/locale.dart @@ -1,15 +1,16 @@ import "package:args/command_runner.dart"; +import "package:discloud/cli/context.dart"; import "package:discloud/extensions/command.dart"; import "package:discloud/utils/messages.dart"; final class UserLocaleCommand extends Command { UserLocaleCommand() { argParser - ..addOption("locale", abbr: "l", valueHelp: context.locale) + ..addOption("locale", abbr: "l", valueHelp: localeName) ..addFlag( "system", abbr: "s", - help: "Use current system language (${context.locale})", + help: "Use current system language ($localeName)", negatable: false, ); } From f4e0682e0a5ed2ae8295aeffb9d1b41e967597dd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 3 Jun 2026 16:46:39 +0000 Subject: [PATCH 3/3] docs: update fd18f77 --- docs/commands.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 394a000..08c2f71 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -562,8 +562,8 @@ Set your locale Usage: discloud user locale [arguments] -h, --help Print this usage information. --l, --locale= --s, --system Use current system language (en-US) +-l, --locale= +-s, --system Use current system language (en_US) ``` ### zip