Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ This product includes software developed by third parties.
See licenses below for details.

================================================================================
THIRD-PARTY SOFTWARE LICENSES

# THIRD-PARTY SOFTWARE LICENSES

================================================================================

1. PySide6 & shiboken6
Expand Down
26 changes: 22 additions & 4 deletions docs/app_i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ tt_build_all: Démarrer la compilation

The recommended pattern is:

1. create the widget
2. attach i18n properties to it
3. let `pycompiler_ark/Ui/i18n.py` resolve the active language
4. let the generic walker read the widget properties and call `translate(self.id, ...)`
1. **Naming Convention (Automatic)**:
Name your widget using one of the following prefixes to have it translated automatically:
- `btn_<key>` (e.g. `btn_select_folder` translates using `select_folder` and resolves its tooltip as `tt_select_folder`).
- `action_<key>` (e.g. `action_select_workspace`).
- `tab_<key>` (e.g. `tab_hello`).

2. **Explicit Properties**:
Attach explicit `i18n_*` properties to the widget (via PySide's `.setProperty()` or inside the `.ui` file) if you want to override the default convention lookup.

If you need to attach properties manually, use:

Expand Down Expand Up @@ -91,6 +95,20 @@ Typical use cases:
- `i18n_format_attr`: value inserted into a translated template, such as a workspace path
- `i18n_none_key`: fallback text when the dynamic attribute is empty

## **When to Use What**

- **Naming Conventions (`btn_*`, `action_*`, `tab_*`)**:
- **When**: Building standard persistent UI elements like buttons, actions, and tab widgets.
- **Why**: Zero configuration. Just name the widget correctly and the system translates the text and tooltip automatically.

- **Explicit Properties (`i18n_text_key`, `i18n_format_attr`, etc.)**:
- **When**: Surcharging standard convention lookups, setting up line edit placeholder keys, formatting strings with dynamic values (like `{path}` via `i18n_format_attr`), or handling system preference toggles.
- **Why**: Allows advanced dynamic text formatting and fallback keys (`i18n_none_key`).

- **Direct API `translate(self.id, key, default)`**:
- **When**: Translating non-persistent text dynamically in Python code (e.g. dialog messages, warning/error popups, dynamic log outputs).
- **Why**: Best for ad-hoc strings that do not belong to static UI widgets.

## **Language Change Flow**

When the user changes the language:
Expand Down
10 changes: 6 additions & 4 deletions pycompiler_ark/Core/Compiler/engine_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,12 @@ def append(self, message: str):
# message is already formatted by log_i18n_level
self.log_cb("", message)

def _safe_log(self, text, text_en=None, level=None):
# Fallback for VenvManager
msg = text_en if text_en else text
self.log_cb("", msg)
def log_i18n(self, fr: str, en: str, level: str | None = None):
from pycompiler_ark.Ui.i18n import log_i18n
log_i18n(self, fr, en, level)

def log_i18n_level(self, level: str, fr: str, en: str):
self.log_i18n(fr, en, level)

def tr(self, fr, en):
return en # Simple fallback
Expand Down
Loading