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

Few changes to allow the support of right to left languages #658

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions UM/Qt/Bindings/i18nCatalogProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, parent = None):
self._i18nc_function = self._wrapFunction(engine, self, self._call_i18nc)
self._i18np_function = self._wrapFunction(engine, self, self._call_i18np)
self._i18ncp_function = self._wrapFunction(engine, self, self._call_i18ncp)
self._i18nIsRightToLeft_function = self._wrapFunction(engine, self, self._call_i18nIsRightToLeft)

def setName(self, name):
if name != self._name:
Expand Down Expand Up @@ -51,6 +52,10 @@ def i18np(self):
def i18ncp(self):
return self._i18ncp_function

@pyqtProperty(QJSValue, notify = nameChanged)
def i18nIsRightToLeft(self):
return self._i18nIsRightToLeft_function

@pyqtSlot(str, result = str)
def _call_i18n(self, message):
return self._catalog.i18n(message)
Expand All @@ -67,6 +72,10 @@ def _call_i18np(self, single, multiple, counter):
def _call_i18ncp(self, context, single, multiple, counter):
return self._catalog.i18ncp(context, single, multiple, counter)

@pyqtSlot(result= bool)
def _call_i18nIsRightToLeft(self):
return self._catalog.i18nIsRightToLeft()

def _wrapFunction(self, engine, this_object, function):
"""Wrap a function in a bit of a javascript to re-trigger a method call on signal emit.

Expand Down
2 changes: 2 additions & 0 deletions UM/Qt/qml/UM/RecolorImage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Item
property alias source: img.source
property alias color: overlay.color
property alias sourceSize: img.sourceSize
property alias mirror: img.mirror

Image
{
Expand All @@ -20,6 +21,7 @@ Item
visible: false
sourceSize.width: parent.width
sourceSize.height: parent.height
layer.enabled: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change this to layer.enabled: mirror to save some rendering performance. These images are used a lot (e.g. with every setting) so performance is important.

}

ColorOverlay {
Expand Down
12 changes: 12 additions & 0 deletions UM/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ def i18ncp(self, context: str, single: str, multiple: str, counter: int, *args:
translated = translated.format(counter, args)
return self._replaceTags(translated)

def i18nIsRightToLeft(self):
"""Returns true if the language is right to left language.

It uses the variable Language-Direction in the language metadata to detrmine direction
if direction not specified it will default to false

:return: True if the language is right to left otherwise False
"""
if(self.__translation is not None):
return self.__translation.info().get("Language-Direction","ltr")=="rtl"
return False

def _replaceTags(self, string: str) -> str:
"""Replace formatting tags in the string with globally-defined replacement
values.
Expand Down