Skip to content

Реализовать поддержку двух языков (русский + английский) в пользовате…#4

Open
temailkaev wants to merge 1 commit into
mainfrom
5zadanie
Open

Реализовать поддержку двух языков (русский + английский) в пользовате…#4
temailkaev wants to merge 1 commit into
mainfrom
5zadanie

Conversation

@temailkaev

Copy link
Copy Markdown
Owner

…льском интерфейсе приложения, обеспечив возможность переключения языка через меню. Также реализовал кэширование объектов MessageFormat для ускорения форматирования сообщений и провести сравнительный анализ производительности.


public class I18N {
private static final String BUNDLE_NAME = "localization.Messages";
private static ResourceBundle bundle;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bundle и currentLocale — изменяемые static без volatile. setLocale() пишет их, а format()/get() читают (потенциально из
EDT и других потоков). Стоит пометить volatile или синхронизировать

return currentLocale;
}

public static String get(String key) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

et() — bundle.getString(key) бросит MissingResourceException при отсутствии ключа, фолбэка нет. Хорошо бы дефолт лог

import java.text.MessageFormat;
import java.util.Locale;

public class PerformanceTest {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

бенчмарк класс с main() попал в продакшн исходники (src/localization). Его место — в тестах отдельном модуле или вообще удалить

// 1. Formatter (String.format)
long start = System.nanoTime();
for (int i = 0; i < ITERATIONS; i++) {
String.format("Позиция X: %.2f, Y: %.2f, Направление: %.3f", x, y, dir);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сравнение некорректное: String.format("...%.2f...") реально форматирует числа, а MessageFormat с шаблоном {0} просто вставляет toString() double. Это не «честный» бенчмарк, вывод про ускорение в N раз вводит в заблуждение

log.ready=\u0420\u043e\u0431\u043e\u0442 \u0433\u043e\u0442\u043e\u0432 \u043a \u0440\u0430\u0431\u043e\u0442\u0435
log.newline=\u041d\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430
log.closing=\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443
benchmark.key=\u041f\u043e\u0437\u0438\u0446\u0438\u044f X: {0}, Y: {1}, \u041d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435: {2} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

служебный ключ для бенчмарка не должен лежать в продакшн-ресурсах

log.ready=Robot is ready
log.newline=New line
log.closing=Application is shutting down
benchmark.key=Position X: {0}, Y: {1}, Direction: {2} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

служебный ключ для бенчмарка не должен лежать в продакшн-ресурсах

return viewMenu;
}

private void switchLanguage(Locale locale) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private void switchLanguage(Locale locale) — выбранный язык не сохраняется между запусками, хотя в проекте уже есть WindowStateStore

@ASHGOLDOFFICIAL ASHGOLDOFFICIAL May 30, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+

updateUIFromBundle();
}

private void updateUIFromBundle() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateUIFromBundle() — ручное и дублирующее перечисление всех setText(). При добавлении пункта меню легко забыть строку. Можно вынести в цикл/мапу «компонент → ключ»

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Каждый элемент меню пусть обновляет себя сам. Иначе опять получается гигантский класс.

} catch (Exception ex) {}
});
showCoordsItem = new JMenuItem(I18N.get("menu.windows.coords"));
showCoordsItem.addActionListener(e -> { coordinatesWindow.setVisible(true); try { coordinatesWindow.setIcon(false); } catch (Exception ex) {} });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch (Exception ex) {} (в showCoordsItem/showGameItem/showLogItem) — пустые catch молча проглатывают исключения (setIcon). Хотя бы лог

…льском интерфейсе приложения, обеспечив возможность переключения языка через меню. Также реализовать кэширование объектов MessageFormat для ускорения форматирования сообщений и провести сравнительный анализ производительности.
String.format("%.1f", (double)msgFormatUncachedTime / msgFormatCachedTime) +
" раз по сравнению с MessageFormat без кэша");
}
}//ауе No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants