vorta icon indicating copy to clipboard operation
vorta copied to clipboard

Resolve #1242 Add translations to treeView columns

Open delfino-nunez opened this issue 3 years ago • 7 comments

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.

Selection_002

delfino-nunez avatar Mar 30 '22 04:03 delfino-nunez

Instead you can use translate which you can import from vorta.i18n. It is good practice to translate strings where they are defined. Applied to this PR, you should change tree_view.py instead of extract_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

delfino-nunez avatar Mar 31 '22 06:03 delfino-nunez

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.

real-yfprojects avatar Apr 01 '22 11:04 real-yfprojects

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?

delfino-nunez avatar Apr 03 '22 04:04 delfino-nunez

You wrap the strings in the list column_names with trans_late. In TreeModel.headerData you wrap self.column_names[section] with self.tr.

real-yfprojects avatar Apr 03 '22 05:04 real-yfprojects

You wrap the strings in the list column_names with trans_late. In TreeModel.headerData you wrap self.column_names[section] with self.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.

delfino-nunez avatar Apr 13 '22 05:04 delfino-nunez

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.

real-yfprojects avatar Apr 13 '22 06:04 real-yfprojects

Are you still on this? @delfino-nunez

real-yfprojects avatar Jun 29 '22 19:06 real-yfprojects

Closing since the source changed dramatically, fixing translations as well.

real-yfprojects avatar Nov 10 '22 19:11 real-yfprojects