Repository: spyder-ide/spyder
Pull request: PR: Fix error when launching Preferences in Chinese
<!--- Make sure to read the Contributing Guidelines:                   --->
<!--- https://github.com/spyder-ide/spyder/blob/master/CONTRIBUTING.md --->
<!--- and follow PEP 8, PEP 257 and Spyder's code style:               --->
<!--- https://github.com/spyder-ide/spyder/wiki/Dev:-Coding-Style      --->

## Description of Changes

Fix the error than appear when trying to run preferences when spyder is in chinese.

<!--- Explain what you've done and why --->




### Issue(s) Resolved

<!--- List the issue(s) below, in the form "Fixes #1234"; one per line --->

Fixes #9390


### Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the [Developer Certificate of Origin](https://developercertificate.org)
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

<!--- TYPE YOUR USER/NAME AFTER THE FOLLOWING: --->
I certify the above statement is true and correct: Steff456

<!--- Thanks for your help making Spyder better for everyone! --->


Problem statement:
Error when launching Preferences in Chinese
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

1. Download Spyder 4.0.0b2 from conda
2. Start Spyder
3. Launch the preference window and then an error report window shows. However, the preference window seems working correctly.

### Traceback
```python-traceback
    widget = plugin.create_configwidget(dlg)
    configwidget.initialize()
    self.setup_page()
    "separate window.") % (inline, automatic))
TypeError: not all arguments converted during string formatting
```

## Versions

* Spyder version: 4.0.0b2 
* Python version: 3.6.7
* Qt version: 5.9.7
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```
pygments >=2.0     :  2.3.1 (OK)
qdarkstyle >=2.6.4 :  2.6.8 (OK)
sphinx >=0.6.6     :  2.0.1 (OK)
pyls >=0.19.0;<0.25:  0.24.0 (OK)
nbconvert >=4.0    :  5.5.0 (OK)
pandas >=0.13.1    :  0.24.2 (OK)
numpy >=1.7        :  1.16.3 (OK)
sympy >=0.7.3      :  1.4 (OK)
cython >=0.21      :  0.29.7 (OK)
qtconsole >=4.2.0  :  4.4.4 (OK)
IPython >=4.0      :  7.5.0 (OK)
matplotlib >=2.0.0 :  3.0.3 (OK)
pylint >=0.25      :  2.3.1 (OK)
```

Hints from issue discussion:
Please run in a terminal (cmd.exe)

    spyder --reset

and try again.
> 
> 
> Please run in a terminal (cmd.exe)
> 
> ```
> spyder --reset
> ```
> 
> and try again.

All things are still the same.
Are you using Spyder in Chinese?
> 
> 
> Are you using Spyder in Chinese?

Yes
Ok, I guessed that. Thanks for the confirmation.

We'll fix this error in our next beta.
@steff456, the idea here is to add the missing string replacement here

https://github.com/spyder-ide/spyder/blob/c68f2f337253b8185fc5fbbd099a09c98de15afa/spyder/locale/zh_CN/LC_MESSAGES/spyder.po#L2419-L2426

You can see that at the end of line 2425 there's a `<b>`, when it should be `<b>%s</b>`.

After doing that change, please go to

    Preferences > General > Advanced settings > Language

select each one of last two (I don't know which one is Chinese) and test that our Preferences can open without problems after the restart that changes the language.

Commit message: fix chinese preferences

Patch to review:
diff --git a/spyder/locale/zh_CN/LC_MESSAGES/spyder.po b/spyder/locale/zh_CN/LC_MESSAGES/spyder.po
index 662a8d39dcf..ea7cb2d5bd2 100644
--- a/spyder/locale/zh_CN/LC_MESSAGES/spyder.po
+++ b/spyder/locale/zh_CN/LC_MESSAGES/spyder.po
@@ -2422,8 +2422,8 @@ msgid ""
 "please select <b>%s</b> to put graphics inside the console or <b>%s</b> to "
 "interact with them (through zooming and panning) in a separate window."
 msgstr ""
-"确定如何在控制台中显示图形。 如果不确定，请选择<b>%s</b>将图形放入控制台或<b>"
-"％s</b>以在单独的窗口中与它们进行交互（如缩放和平移）。"
+"确定如何在控制台中显示图形。 如果不确定，请选择<b>%s</b>将图形放入控制台或<b>％s</b>"
+"以在单独的窗口中与它们进行交互（如缩放和平移）。"
 
 #: spyder/plugins/ipythonconsole.py:405
 msgid "Backend:"
diff --git a/spyder/plugins/ipythonconsole/confpage.py b/spyder/plugins/ipythonconsole/confpage.py
index 6545533c954..83e3a23a2c2 100644
--- a/spyder/plugins/ipythonconsole/confpage.py
+++ b/spyder/plugins/ipythonconsole/confpage.py
@@ -113,10 +113,10 @@ def setup_page(self):
         backend_group = QGroupBox(_("Graphics backend"))
         bend_label = QLabel(_("Decide how graphics are going to be displayed "
                               "in the console. If unsure, please select "
-                              "<b>%s</b> to put graphics inside the "
-                              "console or <b>%s</b> to interact with "
+                              "<b>{0}</b> to put graphics inside the "
+                              "console or <b>{1}</b> to interact with "
                               "them (through zooming and panning) in a "
-                              "separate window.") % (inline, automatic))
+                              "separate window.").format(inline, automatic))
         bend_label.setWordWrap(True)
 
         backends = [(inline, 0), (automatic, 1), ("Qt5", 2), ("Qt4", 3)]
@@ -296,11 +296,11 @@ def setup_page(self):
         autocall_opts = ((_('Off'), 0), (smart, 1), (full, 2))
         autocall_box = self.create_combobox(
                        _("Autocall:  "), autocall_opts, 'autocall', default=0,
-                       tip=_("On <b>%s</b> mode, Autocall is not applied if "
+                       tip=_("On <b>{0}</b> mode, Autocall is not applied if "
                              "there are no arguments after the callable. On "
-                             "<b>%s</b> mode, all callable objects are "
+                             "<b>{1}</b> mode, all callable objects are "
                              "automatically called (even if no arguments are "
-                             "present).") % (smart, full))
+                             "present).").format(smart, full))
 
         autocall_layout = QVBoxLayout()
         autocall_layout.addWidget(autocall_label)


Code review comments:
diff_hunk: @@ -2422,8 +2422,8 @@ msgid ""
 "please select <b>%s</b> to put graphics inside the console or <b>%s</b> to "
 "interact with them (through zooming and panning) in a separate window."
 msgstr ""
-"确定如何在控制台中显示图形。 如果不确定，请选择<b>%s</b>将图形放入控制台或<b>"
-"％s</b>以在单独的窗口中与它们进行交互（如缩放和平移）。"
+"确定如何在控制台中显示图形。 如果不确定，请选择<b>%s</b>将图形放入控制台或<b>％s</b>"
+"以在单独的窗口中与它们进行交互（如缩放和平移）。"
path: spyder/locale/zh_CN/LC_MESSAGES/spyder.po
text: @user1:
@author, I found the error. The real reason for this is that the symbol used by the translator on the second replacement (`％`) is not a regular percentage symbol (`%`) (I don't know why).

Therefore, please leave this string as it was and simply change that symbol. After doing that, you'll see more errors like this one to appear too, so please also fix them.

Something I forgot to tell you is that you need to use a translation program (like `poedit`) to update the translation (i.e. to generate a new `.mo` file) after making changes to source translation file (i.e. the `.po` file).

So in this PR you need to submit both the new `po` and mo files.

@user1:
In other words, you need to open this file in Poedit, make your changes and save it. That will automatically generate a new `mo` file for you.