vorta
vorta copied to clipboard
Resolve #1242 Add translations to treeView columns
I'm not sure if this is the right approach for these dialogs since the translate functions can't be used on the partial tree_view.py file.
Let me know if this is not the right way.

Instead you can use
translatewhich you can import fromvorta.i18n. It is good practice to translate strings where they are defined. Applied to this PR, you should changetree_view.pyinstead ofextract_dialog.py.
But you can't call translate without init_translate right? and also you can't init_translate because you can't pass the app instance.
so how do you call translate from this class?
Shouldn't the columns be sent when the TreeModel is used, like LoadingButton?
self.createStartBtn = LoadingButton(self.tr("Start Backup"))
File "/home/delfino/vorta/src/vorta/views/diff_result.py", line 12, in <module>
from vorta.views.partials.tree_view import TreeModel
File "/home/delfino/vorta/src/vorta/views/partials/tree_view.py", line 192, in <module>
class TreeModel(QAbstractItemModel):
File "/home/delfino/vorta/src/vorta/views/partials/tree_view.py", line 195, in TreeModel
column_names = [translate("test","Name"),"Modified","Size"]
File "/home/delfino/vorta/src/vorta/i18n/__init__.py", line 77, in translate
return application.translate(*args, **kwargs)
NameError: name 'application' is not defined
I see.
Then this is one of the rare cases where trans_late has to be used where the strings are defined. Later when passing the header strings to the table view, self.tr has to be called on them.
I can use trans_late but in the end it will not be translated...
so the question here is if the columns names should be defined in the tree_view.py file or they should be defined for each call of the TreeModel?
I know that's not the best way, but the way trans_late is defined will not do anything for the translation.
what do you think?
You wrap the strings in the list column_names with trans_late. In TreeModel.headerData you wrap self.column_names[section] with self.tr.
You wrap the strings in the list
column_nameswithtrans_late. InTreeModel.headerDatayou wrapself.column_names[section]withself.tr.
I tried to do it this way but doesn't work.
column_names = [trans_late("TreeModel","Name"), trans_late("TreeModel","Modified"), trans_late("TreeModel","Size")]
and then
return self.tr(self.column_names[section])
doesn't fail, but doesn't translate.
Also it doesn't generate new translations for the columns when running make translations-from-source...
So I wonder if I'm doing something wrong or the translation doesn't work in this case.
Patch the following:
diff --git a/Makefile b/Makefile
index 7cae6d0..62f258f 100644
--- a/Makefile
+++ b/Makefile
@@ -37,8 +37,7 @@ bump-version: ## Tag new version. First set new version number in src/vorta/_ve
translations-from-source: ## Extract strings from source code / UI files, merge into .ts.
pylupdate5 -verbose -translate-function trans_late \
- ${VORTA_SRC}/*.py ${VORTA_SRC}/views/*.py ${VORTA_SRC}/borg/*.py \
- ${VORTA_SRC}/store/*.py ${VORTA_SRC}/assets/UI/*.ui \
+ $$(find ${VORTA_SRC} -regex ".*[.]\(py\|ui\)") \
-ts ${VORTA_SRC}/i18n/ts/vorta.en.ts
translations-push: translations-from-source ## Upload .ts to Transifex.
Are you still on this? @delfino-nunez
Closing since the source changed dramatically, fixing translations as well.