-
Notifications
You must be signed in to change notification settings - Fork 4
Fr] create and fill the localization ua.properties file #81 #101
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| import picocli.CommandLine; | ||
| import picocli.CommandLine.Command; | ||
| import ua.com.javarush.gnew.m2.cli.commands.*; | ||
| import ua.com.javarush.gnew.m2.service.LocalizationService; | ||
| import java.util.Locale; | ||
|
|
||
| @Command( | ||
| name = "phonebook", | ||
|
|
@@ -13,21 +15,24 @@ | |
| description = "CLI для управління контактами в телефонній книзі") | ||
| public class PhoneBookCLI implements CliCommand { | ||
|
|
||
| @Override | ||
| LocalizationService localizationService = new LocalizationService(Locale.getDefault()); | ||
|
|
||
| @Override | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Це не сюди, це треба зробити у класі PhoneBookContext. Також ти встановлюєш локаль з стстеми, а в нас заплановано що локаль вибирає користувач і зберігає у файлі налаштувань. отже локаль треба взяти звідти. |
||
| public Integer call() { | ||
| System.out.println("Використовуйте одну з команд: user, add, search, edit, delete, list"); | ||
| System.out.println(localizationService.getMessage("app.commands").replace("{0}","user, add, search, edit, delete, list, locale")); | ||
| return 0; | ||
| } | ||
|
|
||
|
|
||
| public static int init(String[] args) { | ||
| return new CommandLine(getBean(PhoneBookCLI.class)) | ||
| .addSubcommand("add", getBean(AddContact.class)) | ||
| .addSubcommand("search", getBean(SearchContact.class)) | ||
| .addSubcommand("edit", getBean(EditContact.class)) | ||
| .addSubcommand("delete", getBean(DeleteContact.class)) | ||
| .addSubcommand("list", getBean(ListContacts.class)) | ||
| .addSubcommand("user", getBean(SetUser.class)) | ||
| .addSubcommand("locale", getBean(SetLocale.class)) | ||
| .addSubcommand("command.add", getBean(AddContact.class)) | ||
| .addSubcommand("command.search", getBean(SearchContact.class)) | ||
| .addSubcommand("command.edit", getBean(EditContact.class)) | ||
| .addSubcommand("command.delete", getBean(DeleteContact.class)) | ||
| .addSubcommand("command.list", getBean(ListContacts.class)) | ||
| .addSubcommand("command.user", getBean(SetUser.class)) | ||
| .addSubcommand("command.locale", getBean(SetLocale.class)) | ||
| .execute(args); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Це не текст для користвача це назви команд для picocli їх не треба перекладати. Думаю так воно не заведется. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,18 @@ | ||
| package ua.com.javarush.gnew.m2.cli.commands; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.Locale; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JacksonInject; | ||
| import picocli.CommandLine; | ||
| import ua.com.javarush.gnew.m2.cli.CliCommand; | ||
| import ua.com.javarush.gnew.m2.configuration.PhoneBookContext; | ||
| import ua.com.javarush.gnew.m2.service.LocalizationService; | ||
| import ua.com.javarush.gnew.m2.service.SettingsServiceInterface; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| @CommandLine.Command( | ||
| name = "locale", | ||
| aliases = {"-l", "--locale"}, | ||
|
|
@@ -14,20 +21,32 @@ | |
| public class SetLocale implements CliCommand { | ||
|
|
||
| private final SettingsServiceInterface settingsService = | ||
| PhoneBookContext.getBean(SettingsServiceInterface.class); | ||
| PhoneBookContext.getBean(SettingsServiceInterface.class); | ||
|
|
||
| LocalizationService localizationService = new LocalizationService(Locale.getDefault()); | ||
|
|
||
| @CommandLine.Parameters(index = "0", description = "language", arity = "1") | ||
| private String newLocale; | ||
|
|
||
| @Override | ||
| public Integer call() { | ||
| try { | ||
| settingsService.setLocale(newLocale); | ||
| System.out.println("Локаль установлена на: " + newLocale); | ||
| return 0; | ||
| } catch (IOException e) { | ||
| System.err.println("Ошибка при установке локали: " + e.getMessage()); | ||
| return 1; | ||
|
|
||
|
|
||
| @Override | ||
| public Integer call() { | ||
| try { | ||
| Locale locale = new Locale(newLocale); | ||
| if (!Arrays.asList(Locale.getAvailableLocales()).contains(locale)) { | ||
| System.err.println(localizationService.getMessage("error.dontUse.notfound").replace("{0}", newLocale)); | ||
| return 1; | ||
| } | ||
| settingsService.setLocale(newLocale); | ||
| localizationService.setLocale(new Locale(newLocale)); | ||
| System.out.println(localizationService.getMessage("success.locale.changed").replace("{0}", newLocale)); | ||
| System.out.println(localizationService.getMessage("locale.current").replace("{0}", newLocale)); | ||
| return 0; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ОК. хоча програма закінчить роботу після виконання цєї команди. Чи є потреба міняти поточну локаль? |
||
|
|
||
| } catch (IOException e) { | ||
| System.err.println(localizationService.getMessage("error.command.notfound").replace("{0}", newLocale)); | ||
| return 1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| RU |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Загальні повідомлення | ||
| app.description=CLI для управління контактами в телефонній книзі | ||
| app.version=Телефонна книга CLI 1.0 | ||
| app.commands=Використовуйте одну з команд: {0} | ||
|
|
||
| # Команди | ||
| command.add=додати | ||
| command.search=пошук | ||
| command.edit=редагувати | ||
| command.delete=видалити | ||
| command.list=список | ||
| command.user=користувач | ||
| command.locale=мова | ||
|
|
||
| # Підказки та помилки | ||
| error.command.notfound=Команду не знайдено: {0} | ||
| error.missing.argument=Відсутній обов'язковий аргумент: {0} | ||
| success.locale.changed=Мову успішно змінено на {0} | ||
| error.dontUse.notfound = невідома команда: {0} | ||
|
|
||
|
|
||
| # Мови | ||
| locale.current=Поточна мова: {0} | ||
| locale.available=Доступні мови: {0} | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ОК . Але це тільки маленький шматочек тут потрібно внести всі тексти для користувача. |
||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нащо це тут? Схоже він ніде не використовуєтся.