mitchcurtis / slate

Pixel Art Editor
GNU General Public License v3.0
1.07k stars 103 forks source link

Add arabic translation for slate #126

Closed wow2006 closed 5 years ago

wow2006 commented 5 years ago

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

mitchcurtis commented 5 years ago

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 commented 5 years ago

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

mitchcurtis commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

commit f1248d727b9c1fb269e7d4e10349f43ad8f048fa
Author: Mitch Curtis <mitch.curtis@qt.io>
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 commented 5 years ago

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 commented 5 years ago

I can not translate any more :D

mitchcurtis commented 5 years ago

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 commented 5 years ago

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

wow2006 commented 5 years ago

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

mitchcurtis commented 5 years ago

No worries, I already fixed it. :D