Skip to content
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

[FEATURE]: use Qt linguist for translation #5

Open
nepvibes opened this issue Aug 27, 2024 · 1 comment
Open

[FEATURE]: use Qt linguist for translation #5

nepvibes opened this issue Aug 27, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@nepvibes
Copy link

** Feature Description 【特性详细描述】**

The current default language is set to Chinese.
To make our application more accessible to a wider audience,
we should include a translation system and set English as the default language.
We can use Qt Linguist to create .ts files for translations using lupdate.

QTranslator translator; if (translator.load(QLocale(), "FlowD", "_", ":/translations")) { app.installTranslator(&translator); }

For making strings translatable, we can use the tr function. Here’s an example:

void DownloadItemWidget::onBtnSuspendClicked(bool checked) { if (checked) { ui->btnSuspend->setText(tr("Continue")); /* When the button is checked, change the text to "Continue" TODO: Add logic to resume the download */ } else { ui->btnSuspend->setText(tr("Pause")); /* When the button is unchecked, change the text to "Pause" TODO: Add logic to pause the download */ } }

This setup will ensure that our application supports multiple languages,
with English as the default. The lupdate tool will help generate the .ts files needed for translation.

@ProgramCX ProgramCX added good first issue Good for newcomers enhancement New feature or request labels Aug 27, 2024
@ProgramCX ProgramCX self-assigned this Aug 27, 2024
@ProgramCX
Copy link
Collaborator

** Feature Description 【特性详细描述】**

The current default language is set to Chinese. To make our application more accessible to a wider audience, we should include a translation system and set English as the default language. We can use Qt Linguist to create .ts files for translations using lupdate.

QTranslator translator; if (translator.load(QLocale(), "FlowD", "_", ":/translations")) { app.installTranslator(&translator); }

For making strings translatable, we can use the tr function. Here’s an example:

void DownloadItemWidget::onBtnSuspendClicked(bool checked) { if (checked) { ui->btnSuspend->setText(tr("Continue")); /* When the button is checked, change the text to "Continue" TODO: Add logic to resume the download */ } else { ui->btnSuspend->setText(tr("Pause")); /* When the button is unchecked, change the text to "Pause" TODO: Add logic to pause the download */ } }

This setup will ensure that our application supports multiple languages, with English as the default. The lupdate tool will help generate the .ts files needed for translation.

Thank you for your suggestions. We will change the default language of the UI and code comments to English, utilize the QObject::tr() function, and add support for other languages in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants