Skip to content

Add arabic translation for slate#126

Merged
mitchcurtis merged 8 commits intomitchcurtis:masterfrom
wow2006:master
Jun 13, 2019
Merged

Add arabic translation for slate#126
mitchcurtis merged 8 commits intomitchcurtis:masterfrom
wow2006:master

Conversation

@wow2006
Copy link
Copy Markdown
Contributor

@wow2006 wow2006 commented Jun 9, 2019

I just want to make sure that I working on the right direction.

},
{
value: "Norwegian",
display: "Norsh"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Norsk

-ts $translationDir/slate_en_GB.ts \
$translationDir/slate_no_NB.ts
$translationDir/slate_no_NB.ts \
$translationDir/slate_ar_EG.ts
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please make the indenting for $translationDir/slate_ar_EG.ts align with the previous line.

@mitchcurtis
Copy link
Copy Markdown
Owner

mitchcurtis commented Jun 9, 2019

Looks good so far, just a few nitpicks.

By the way, if you don't intend to add any translated strings in the .ts file yet, it would be good to change the name of the pull request to "Add beginnings of Arabic translation for Slate" or something, just to indicate that the work is ongoing. :) I think the pull request title shows up in the merge commit, that's all.

@wow2006
Copy link
Copy Markdown
Contributor Author

wow2006 commented Jun 9, 2019

I am willing to add arabic string. I just want to know how to switch to arabic first :D

@mitchcurtis
Copy link
Copy Markdown
Owner

Oh, does it still not work? You will need to do something like:

const QLocale locale(mSettings->language());

https://github.com/mitchcurtis/slate/blob/master/app/application.cpp#L138

@wow2006
Copy link
Copy Markdown
Contributor Author

wow2006 commented Jun 10, 2019

I run slate from qtcreator. mSettings->language() return English every time what every I do. I pass language manually for now. Still, Did not change the language. I passed Arabic ts file manually so I can preview. I am working on the translation still It's so boring.

@mitchcurtis
Copy link
Copy Markdown
Owner

I run slate from qtcreator. mSettings->language() return English every time what every I do. I pass language manually for now. Still, Did not change the language. I passed Arabic ts file manually so I can preview.

Hmmm, that's odd. I'll have to give it a try later today. :)

I am working on the translation still It's so boring.

Haha yeah, it is! :D

@mitchcurtis
Copy link
Copy Markdown
Owner

OK, I got it working. Please apply this patch:

commit f1248d727b9c1fb269e7d4e10349f43ad8f048fa
Author: Mitch Curtis <[email protected]>
Date:   Tue Jun 11 19:10:45 2019 +0200

    Get it working

diff --git a/app/application.cpp b/app/application.cpp
index 983c821..2af55db 100644
--- a/app/application.cpp
+++ b/app/application.cpp
@@ -135,7 +135,7 @@ Application::Application(int &argc, char **argv, const QString &applicationName)
     }
 
     QTranslator translator;
-    const QLocale locale;
+    const QLocale locale(mSettings->language());
     QDir translationsDir = QDir::current();
     translationsDir.cdUp();
     translationsDir.cd(QStringLiteral("Translations"));
diff --git a/app/qml/ui/OptionsDialog.qml b/app/qml/ui/OptionsDialog.qml
index 4647c0c..bee4158 100644
--- a/app/qml/ui/OptionsDialog.qml
+++ b/app/qml/ui/OptionsDialog.qml
@@ -22,6 +22,7 @@ Dialog {
     onAboutToShow: clearChanges()
 
     function applyAllSettings() {
+        settings.language = languageComboBox.model[languageComboBox.currentIndex].value
         settings.loadLastOnStartup = loadLastCheckBox.checked
         settings.gesturesEnabled = enableGesturesCheckBox.checked
         settings.penToolRightClickBehaviour =
@@ -42,6 +43,7 @@ Dialog {
     }
 
     function clearChanges() {
+        languageComboBox.currentIndex = languageComboBox.indexForValue(settings.language)
         loadLastCheckBox.checked = settings.loadLastOnStartup
         enableGesturesCheckBox.checked = settings.gesturesEnabled
         penToolRightClickBehaviourComboBox.currentIndex =
@@ -112,29 +114,30 @@ Dialog {
                         textRole: "display"
                         currentIndex: indexForValue(settings.language)
 
+                        Layout.fillWidth: true
+
+                        function indexForValue(value) {
+                            for (var i = 0; i < model.length; ++i) {
+                                if (model[i].value === value)
+                                    return i;
+                            }
+                            return -1;
+                        }
+
                         model: [
                             {
-                                value: "English",
+                                value: "en_GB",
                                 display: "English"
                             },
                             {
-                                value: "Norwegian",
-                                display: "Norsh"
+                                value: "nb_NO",
+                                display: "Norsk"
                             },
                             {
-                                value: "Arabic",
+                                value: "ar_EG",
                                 display: "العربيه"
                             }
                         ]
-
-                        Layout.fillWidth: true
-                        function indexForValue(value) {
-                            for (var i = 0; i < model.length; ++i) {
-                                if (model[i].value === value)
-                                    return i;
-                            }
-                            return -1;
-                        }
                     }
 
                     Label {
diff --git a/lib/applicationsettings.cpp b/lib/applicationsettings.cpp
index 784af55..b542571 100644
--- a/lib/applicationsettings.cpp
+++ b/lib/applicationsettings.cpp
@@ -33,6 +33,30 @@ ApplicationSettings::ApplicationSettings(QObject *parent) :
     qCDebug(lcApplicationSettings) << "Loading settings from" << fileName();
 }
 
+QString ApplicationSettings::defaultLanguage() const
+{
+    return "en_GB";
+}
+
+QString ApplicationSettings::language() const
+{
+     return contains("language") ? value("language").toString() : defaultLanguage();
+}
+
+void ApplicationSettings::setLanguage(const QString &language)
+{
+    const QVariant existingValue = value("language");
+    QString existingStringValue = defaultLanguage();
+    if (contains("language"))
+        existingStringValue = existingValue.toBool();
+
+    if (language == existingStringValue)
+        return;
+
+    setValue("language", language);
+    emit languageChanged();
+}
+
 bool ApplicationSettings::loadLastOnStartup() const
 {
     return contains("loadLastOnStartup") ? value("loadLastOnStartup").toBool() : defaultLoadLastOnStartup();
@@ -1069,20 +1093,3 @@ void ApplicationSettings::setFullScreenToggleShortcut(const QString &shortcut)
 {
     SET_SHORTCUT("fullScreenToggleShortcut", defaultFullScreenToggleShortcut, fullScreenToggleShortcutChanged)
 }
-
-constexpr char LanguageName[] = "language";
-QString ApplicationSettings::defaultLanguage() const {
-    return "English";
-}
-
-QString ApplicationSettings::language() const {
-     return contains(LanguageName) ? value(LanguageName).toString() : defaultLanguage();
-}
-
-void ApplicationSettings::setLanguage(const QString &value) {
-    if (language() == value)
-        return;
-
-    setValue(LanguageName, QVariant(value));
-    emit languageChanged();
-}
diff --git a/lib/applicationsettings.h b/lib/applicationsettings.h
index 7d1e733..0d26d5a 100644
--- a/lib/applicationsettings.h
+++ b/lib/applicationsettings.h
@@ -51,6 +51,7 @@ class SLATE_EXPORT ApplicationSettings : public QSettings
     Q_PROPERTY(QColor checkerColour1 READ checkerColour1 WRITE setCheckerColour1 NOTIFY checkerColour1Changed)
     Q_PROPERTY(QColor checkerColour2 READ checkerColour2 WRITE setCheckerColour2 NOTIFY checkerColour2Changed)
     Q_PROPERTY(int penToolRightClickBehaviour READ penToolRightClickBehaviour WRITE setPenToolRightClickBehaviour NOTIFY penToolRightClickBehaviourChanged)
+    Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged)
 
     Q_PROPERTY(QString quitShortcut READ quitShortcut WRITE setQuitShortcut NOTIFY quitShortcutChanged)
     Q_PROPERTY(QString newShortcut READ newShortcut WRITE setNewShortcut NOTIFY newShortcutChanged)
@@ -90,11 +91,14 @@ class SLATE_EXPORT ApplicationSettings : public QSettings
     Q_PROPERTY(QString swatchUpShortcut READ swatchUpShortcut WRITE setSwatchUpShortcut NOTIFY swatchUpShortcutChanged)
     Q_PROPERTY(QString swatchDownShortcut READ swatchDownShortcut WRITE setSwatchDownShortcut NOTIFY swatchDownShortcutChanged)
     Q_PROPERTY(QString fullScreenToggleShortcut READ fullScreenToggleShortcut WRITE setFullScreenToggleShortcut NOTIFY fullScreenToggleShortcutChanged)
-    Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged)
 
 public:
     explicit ApplicationSettings(QObject *parent = nullptr);
 
+    QString defaultLanguage() const;
+    QString language() const;
+    void setLanguage(const QString &language);
+
     bool loadLastOnStartup() const;
     void setLoadLastOnStartup(bool loadLastOnStartup);
     bool defaultLoadLastOnStartup() const;
@@ -312,11 +316,8 @@ public:
     QString fullScreenToggleShortcut() const;
     void setFullScreenToggleShortcut(const QString &shortcut);
 
-    QString defaultLanguage() const;
-    QString language() const;
-    void setLanguage(const QString &value);
-
 signals:
+    void languageChanged();
     void loadLastOnStartupChanged();
     void recentFilesChanged();
     void gridVisibleChanged();
@@ -371,7 +372,6 @@ signals:
     void swatchUpShortcutChanged();
     void swatchDownShortcutChanged();
     void fullScreenToggleShortcutChanged();
-    void languageChanged();
 };
 
 #endif // APPLICATIONSETTINGS_H

@mitchcurtis
Copy link
Copy Markdown
Owner

And yeah, I removed the languageName optimisation - I know it's not good to do it the way I'm currently doing it, but I'd rather be consistent and fix all of the strings in that file at once. :)

@wow2006
Copy link
Copy Markdown
Contributor Author

wow2006 commented Jun 13, 2019

I can not translate any more :D

@mitchcurtis
Copy link
Copy Markdown
Owner

I can not translate any more :D

Haha, understandable! Nice work!

Should I merge it as it is now and apply the patch I mentioned above afterwards?

@mitchcurtis mitchcurtis merged commit 7b3f174 into mitchcurtis:master Jun 13, 2019
@mitchcurtis
Copy link
Copy Markdown
Owner

Let's get it in and I will fix it up afterwards.

@wow2006
Copy link
Copy Markdown
Contributor Author

wow2006 commented Jun 14, 2019

@mitchcurtis Sorry I forget about the patch. I will add it :)

@mitchcurtis
Copy link
Copy Markdown
Owner

No worries, I already fixed it. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants