Skip to content

Added a complete yet concise i18n framework with support for four languages - #471

Open
TangYuanLonelyCat wants to merge 6 commits into
heyman:mainfrom
TangYuanLonelyCat:main
Open

Added a complete yet concise i18n framework with support for four languages#471
TangYuanLonelyCat wants to merge 6 commits into
heyman:mainfrom
TangYuanLonelyCat:main

Conversation

@TangYuanLonelyCat

Copy link
Copy Markdown

Preface

Why did I do this?

Because I like the Heynote project, but when I recommend it to my friends, they often say: "This software is great, too bad there's no Chinese localization." Out of my deep agreement with the project's philosophy, I added an i18n framework and submitted a PR. I sincerely hope this PR can be merged into the main branch – I believe many users will need it.

About using AI assistance

Yes, this PR was generated with AI assistance, specifically in the following areas:

  • Language translation (provided by Doubao AI, a subsidiary of ByteDance, China)
  • Hardcoded string detection (provided by Qwen3-Coder, a subsidiary of Alibaba Group, China)
  • Quick replacement of hardcoded strings (provided by Qwen3-Coder, a subsidiary of Alibaba Group, China)
  • Translation of all comments I wrote from Chinese to English (provided by Doubao AI, a subsidiary of ByteDance, China)

Note: The core i18n framework in this PR was created by myself.

Files modified by these changes

1. New i18n core files

1.1 src/locales/i18n-core.ts

  • Purpose: Build core translation functionality, no Vue dependency, usable in any environment
  • Changes:
    • Define Locale type, supporting 'en', 'zh', 'ja', 'ko', and 'zh-TW' (Traditional Chinese, as a variant of Simplified Chinese, counted under the same language)
    • Import all language files
    • Define messages object to store all language data
    • Implement safeTranslate function, providing safe translation with language fallback and parameter interpolation

1.2 src/locales/i18n.ts

  • Purpose: Build Vue plugin to provide i18n functionality for the app
  • Changes:
    • Import core functions from ./i18n-core
    • Implement createI18n function to create an i18n instance
    • Add language detection logic, supporting language detection from browser and Electron system
    • Provide Vue plugin installation method
    • Create and export a default i18n instance

1.3 Language files

  • Purpose: Provide multilingual support
  • Changes:
    • src/locales/en.js: English language file – includes translations for UI, commands, initial content, and keyboard shortcuts
    • src/locales/zh.js: Simplified Chinese language file – includes translations for UI, commands, initial content, and keyboard shortcuts
    • src/locales/ja.js: Japanese language file – includes translations for UI, commands, initial content, and keyboard shortcuts
    • src/locales/ko.js: Korean language file – includes translations for UI, commands, initial content, and keyboard shortcuts
    • src/locales/zh-TW.js: Traditional Chinese language file – as a variant of Simplified Chinese, it is considered under the same language support. Provides Traditional Chinese translations based on the Simplified Chinese version.

2. Modified application files to support i18n

2.1 electron/initial-content.ts

  • Purpose: Support multilingual initial hint document
  • Changes:
    • Import safeTranslate from ../src/locales/i18n-core
    • Add language detection logic, supporting both development and production modes
    • Use safeTranslate function to translate the initial hint document content
    • Ensure initial content selects language only at initialization

2.2 shared-utils/key-helper.ts

  • Purpose: Support multilingual keyboard shortcut hints
  • Changes:
    • Import safeTranslate from ../src/locales/i18n-core
    • Add getSystemLocale function to get the current language
    • Modify keyHelpStr function to use safeTranslate for translating shortcut hints

2.3 src/editor/commands.js

  • Purpose: Support multilingual commands
  • Changes:
    • Import i18n from ../locales/i18n
    • Modify command descriptions to use i18n.t() for translating command names
    • Use getter properties to ensure command descriptions update when language changes

2.4 Component files

  • Purpose: Support multilingual UI
  • Changes:
    • src/components/BufferSelector.vue: Import i18n, translate UI elements
    • src/components/settings/Settings.vue: Import i18n, translate settings UI
    • src/components/UpdateStatusItem.vue: Import i18n, translate update status
    • src/components/EditBuffer.vue: Import i18n, translate editing UI
    • src/components/App.vue: Import i18n, translate application UI
    • src/components/NewBuffer.vue: Import i18n, translate new buffer UI
    • src/editor/search/InputToggle.vue: Import i18n, translate search UI

Final results

3.1 Language detection

  • Implementation:
    • First try to get language from the browser
    • Then try to get language from the Electron system
    • When an unsupported language is detected, default to English

3.2 Translation system

  • Implementation:
    • Core translation functionality implemented in i18n-core.ts
    • Vue plugin implemented in i18n.ts
    • Supports language fallback – falls back to English when a translation is missing
    • Supports parameter interpolation and simple pluralization

3.3 Multilingual support

  • Implementation:
    • Create separate language files for each language (English, Simplified Chinese, Japanese, Korean), with Traditional Chinese as a variant of Simplified Chinese
    • Define translation key-value pairs in language files
    • Use safeTranslate function to retrieve translations

4. Error handling and compatibility

  1. Language detection optimization: Ensure correct language detection in different environments
  2. Complete translation coverage: Includes UI elements, command palette commands, initial hint document, and keyboard shortcut hints
  3. Error handling: When translation fails, return the original key name to ensure the app does not crash
  4. Backward compatibility: Maintain compatibility with the original API

Summary

  • Multilingual support: Supports four languages – English, Simplified Chinese, Japanese, and Korean. Traditional Chinese is provided as a variant of Simplified Chinese, not counted as a separate language.
  • Complete translation coverage: All visible parts of the application support multiple languages
  • Reliable language detection: Correctly detects language in both development and production modes
  • Modular design: Core translation functionality is decoupled from Vue and can be used in any environment

All modifications have been tested to ensure the stability and reliability of the i18n framework.

屏幕截图 2026-04-11 001331 屏幕截图 2026-04-11 001317 屏幕截图 2026-04-11 001257 屏幕截图 2026-04-11 001251

By TangYuanLonelyCat
This document was summarized by myself and translated by DeepSeek. It has been confirmed that all m
eanings are conveyed accurately.

Added a basic i18n framework for this project. For startup speed and simplicity, no complex i18n dependencies are used. The current i18n.ts is just a demo and cannot be used in production.
* Key features implemented:
- Refactored App.vue to use i18n for delete confirmation message and improved component structure
- Enhanced BufferSelector.vue with i18n support for create new buffer text and improved UI
- Modified EditBuffer.vue to use i18n for move to label and updated component logic
- Updated NewBuffer.vue with i18n support for create in label and improved dialog title handling
- Added i18n support to UpdateStatusItem.vue for all status messages and titles
- Enhanced AddKeyBind.vue with i18n support for all dialog elements and labels
- Updated KeyboardHotkey.vue with i18n support for all modifier key labels
- Refactored Settings.vue to integrate i18n for all settings labels, titles, and options
- Enhanced InputToggle.vue with i18n support for all search toggle tooltips
- Created comprehensive English locale file (en.js) with all application text
- Updated i18n.ts with robust locale detection and safe translation functions
- Added complete Chinese locale file (zh.js) with corresponding translations
- Integrated i18n plugin into main.js for global locale management
- Updated editor cache store with refined comment language and improved code clarity
- Enhanced Heynote store with i18n-ready buffer title handling and improved tab management

The changes provide full internationalization support while maintaining all existing functionality and improving code maintainability through consistent English comments.


Signed-off-by: 孤独の汤圆猫猫 <lemon121410@163.com>

---------

Signed-off-by: 孤独の汤圆猫猫 <lemon121410@163.com>
… the i18n module is imported – i18n framework update – Support for Chinese, Japanese, English, and Korean.

Changed the original import using @ to the relative path import commonly used by heyman, fixing the import failure issue.

Updated the i18n framework; the current i18n framework is more stable.

Added support for four languages: Chinese, Japanese, English, and Korean. Translation support comes from Doubao AI, a subsidiary of China's ByteDance.
…documentation (keyboard shortcut hints)

Added four-language translations for the command palette and initial documentation (keyboard shortcut hints), resolving the hardcoded strings in the original system and fixing the return key/value issue left over from the previous update. All tests are currently working normally.
@TangYuanLonelyCat
TangYuanLonelyCat marked this pull request as draft April 10, 2026 16:20
@TangYuanLonelyCat
TangYuanLonelyCat marked this pull request as ready for review April 10, 2026 16:20
@TangYuanLonelyCat

Copy link
Copy Markdown
Author

Oh, by the way, I might have forgotten to mention that the initial hint document is generated based on the user's system language, not just English.

- Added toggleLeftPanel function and command with i18n support
    - Added translations for toggleLeftPanel in all language files
    - Fixed syntax errors in en.js and zh.js language files

    This update ensures compatibility with the latest main branch while maintaining full i18n support for all languages.
@TangYuanLonelyCat
TangYuanLonelyCat marked this pull request as draft April 19, 2026 11:45
Signed-off-by: 孤独の汤圆猫猫 <lemon121410@163.com>
@TangYuanLonelyCat
TangYuanLonelyCat marked this pull request as ready for review April 19, 2026 11:50
@TangYuanLonelyCat

Copy link
Copy Markdown
Author

OK, I've resolved this conflict, and it can now be merged cleanly.
Still, I'd like to hear your thoughts, @heyman.

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.

1 participant