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 diff --git a/lib/cli/context.dart b/lib/cli/context.dart index 1d1b068..b8cbcfe 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..0511f89 --- /dev/null +++ b/lib/cli/locale.dart @@ -0,0 +1,8 @@ +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..3d16688 100644 --- a/lib/commands/user/locale.dart +++ b/lib/commands/user/locale.dart @@ -1,22 +1,16 @@ -import "dart:io"; - 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 { - 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: localeName) ..addFlag( "system", abbr: "s", - help: "Use current system language ($_localeName)", + help: "Use current system language ($localeName)", negatable: false, ); } @@ -31,9 +25,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");