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

App: Create addTranslatableExportType method #18678

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chennes
Copy link
Member

@chennes chennes commented Dec 22, 2024

NOTE: This is a work-in-progress, but I am sure there are already some things that could be improved, so I am looking for feedback particularly as regards the C++ aspects of this PR. Especially have a look at the way I've written the two string manipulation functions. I played with std::transform and boost::join, but I didn't feel like that made the code any clearer, but it definitely feels like there's a better approach (or maybe that's the Python programmer in me...). Suggestions welcome! Pinging @xtemp09, @jbaehr, @hyarion, @kadet1090 , and anyone else interested. Also, @yorikvanhavre does this seem like a reasonable approach to the problem?


This method aims to solve the problem of untranslatable description strings on file types. Some, but not all, file format description strings contain translatable elements. For example, some languages may translate "FEM mesh formats". Many format descriptions include the words "file," "format," or "mesh" -- these could potentially be replaced with localized versions.

There are two challenges: the first is to prevent translators from accidentally breaking the quite-sensitive formatting of the list of supported extensions. This is achieved by dropping anything that looks like such a list from the string post-translation, and simply recreating it in a known-good format from a list of extensions provided to the new method.

The second challenge is to support retranslation during a single run of the program (e.g. changing the language of the UI while it is running). To achieve this, a caching system is used. Every call to the new method is cached, and when the language changes those calls will be "replayed" both to remove the original entry, and to add the entry in the new language.

This commit implements the Export method and cache, but does not add either the corresponding Input method and cache, the replay of the cache, or the actual code update needed to call this method when a translation is possible.

Unit tests for the new method are added, and some refactoring of a small set of existing tests is included as part of the reorganization of the Application class tests.

This method aims to solve the problem of untranslatable description
strings on file types. Some, but not all, file format description
strings contain translatable elements. For example, some languages
may translate "FEM mesh formats". Many format descriptions include
the words "file," "format," or "mesh" -- these could potentially be
replaced with localized versions.

There are two challenges: the first is to prevent translators from
accidentally breaking the quite-sensitive formatting of the list of
supported extensions. This is achieved by dropping anything that
looks like such a list from the string post-translation, and simply
recreating it in a known-good format from a list of extensions
provided to the new method.

The second challenge is to support retranslation during a single run
of the program (e.g. changing the language of the UI while it is
running). To achieve this, a caching system is used. Every call to
the new method is cached, and when the language changes those calls
are "replayed" both to remove the original entry, and to add the entry
in the new language.

This commit implements the Export method and cache, but does not add
either the corresponding Input method and cache, the replay of the
cache, or the actual code update needed to call this method when
a translation is possible.

Unit tests for the new method are added, and some refactoring of
a small set of existing tests is included as part of the
reorganization of the Application class tests.
@github-actions github-actions bot added the Mod: Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD label Dec 22, 2024
Originally this test file simply defined the appropriate macro, but
since macros leak that can have unexpected side effects on other tests.
It's safer to simply only run that test on the Mac.
@xtemp09
Copy link
Contributor

xtemp09 commented Dec 23, 2024

Is the approach to remove the parentheses and to add them again? If translators are so unreliable, would it be better to translate without extensions and append them later ("Some type (%1)")?

description.pop_back() looks niftier than description.erase(description.end()-1).

@chennes
Copy link
Member Author

chennes commented Dec 23, 2024

Is the approach to remove the parentheses and to add them again? If translators are so unreliable, would it be better to translate without extensions and append them later ("Some type (%1)")?

My thinking was that by providing the whole string, it would give translators more information about what they were translating -- for example, that "FEM mesh formats (*.dat *.inp *.med *.stl *.unv *.vtk *.vtu *.z88)" would be better for translators than just "FEM mesh formats". But maybe your suggestion is enough for translators, using "FEM mesh formats (%1)" -- @kaktusus what do you think? (And it's not that I think all translators are unreliable, but I suspect there will be some temptation to do something like, e.g. add commas to the list, which will break it).

description.pop_back() looks niftier than description.erase(description.end()-1).

Yes, I'll change that.

@hyarion
Copy link
Contributor

hyarion commented Dec 26, 2024

@chennes can this information be provided as an extra-comment to the translators instead?

@chennes
Copy link
Member Author

chennes commented Dec 26, 2024

Yes, as long as we are OK with doubling the lines of code needed to specify an export type: the syntax for those comments adds another line. It is probably preferable to the current duplication, but it isn't clear to me what exactly will help translators the most.

@hyarion
Copy link
Contributor

hyarion commented Dec 26, 2024

@chennes I'm trying to see how extra-comments looks in Crowdin, but I'm having trouble locating a tr(...) with such extra comment, do you know of any?

@xtemp09
Copy link
Contributor

xtemp09 commented Dec 26, 2024

@hyarion, https://doc.qt.io/qt-6/i18n-source-translation.html#add-comments-for-translators


//: Header for bgbsww
creditsHTML +=
tr("This version of FreeCAD is dedicated to the memory of Brad McLean, aka bgbsww.");

https://crowdin.com/editor/freecad/549/en-ru?view=comfortable#6670936


//: Header for the list of companies/organizations in the Credits list.
creditsHTML += tr("Organizations");

https://crowdin.com/editor/freecad/549/en-ru?view=comfortable#6589636

@hyarion
Copy link
Contributor

hyarion commented Dec 26, 2024

I don't think we'll be able to find the perfect solution to a problem that doesn't exist yet.
Any of the options could work, but I would personally prefer to start with a simple solution, and go from there.

I would start with adding extracomments, depending on what we write, that should be enough.

@yorikvanhavre
Copy link
Member

Agree with the comments above!

@kaktusus
Copy link
Contributor

Sorry chennes you waited so long for my answer.

I posted this topic on the forum in the translators section. Maybe someone will also write something interesting.
There I gave my answer.

https://forum.freecad.org/viewtopic.php?style=4&t=94230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mod: Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants