-
Notifications
You must be signed in to change notification settings - Fork 110
Conversation
It is so hard to pass the build :( |
Can you explain your logic for figuring out the system language? I can't really follow your code. |
I did not add code for getting the system language (The system language detecting is already in FreeseerApp.py, but the result was not really been used) |
I'm a big fan of code reuse and not duplicating code. Considering configtool, talkeditor, recordingui, and reporteditor all base themselves on FreeseerApp is there no way to have them all use the same code to set the language rather than having the same 3 lines of code copied to all of the frontends? |
That is what I thought! However, the import of self.config is after initializing FreeseerApp in those tools and editors. Which means I cannot make sure whether the user have a configuration file or not when FreeseerApp is initializing. If it can be guaranteed that moving the config loading into FreeseerApp in the front of the initialization will not have inference on the program. I am glad to do that. |
I say give it a try and see if anything breaks. Edit: you can even do this test in a separate branch in case it does break and you have a path to go back to. |
I'll also mention again that you don't need a dummy language. You can make your auto detected language be the default value in |
The tricky thing is that if I do not use the dummy language, I will not be aware of whether the default language in the config is the initial value (the user does not have a config file yet) or the user chose that language by force (then I should not change that). Now if it is a dummy language. I know that the user does not have a config file. Or should I add another method in the config class to return a bool of whether there is a config file? |
You are over thinking this. The point of a default config value is that it will be used when there is no config file. |
If this weren't the case, then your dummy language wouldn't even work. |
Actually this function will only work when the user open Freeseer for the first time. At that time, there is definitely no config file. So the dummy language will work and the language will be auto detected. Once there is a config file, it will be either that the language has already been auto chosen in the previous running or the user forced to change the default language in the ConfigTool. Since the user's choice always has higher priority according to #601 , The auto language function will not run and the dummy language will also be not used. |
What are your thoughts on this? class FreeseerSettings(Config):
...
default_language = options.StringOption(str(QLocale.system().name())) |
@mtomwing |
Yeah, you can definitely refactor the config stuff to be in FreeseerApp. |
30cc117
to
9e09fbd
Compare
@mtomwing |
@@ -26,6 +26,7 @@ | |||
|
|||
from freeseer.framework.config.core import Config | |||
from freeseer.framework.config.profile import ProfileManager | |||
from PyQt4.QtCore import QLocale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imports are ordered like so:
# modules in stdlib
import os
# third party modules
import PyQt
# freeseer modules
import freeseer
@mtomwing |
This version has some problem, the QDir in settings.py does not read the target language files. i upload this version cause I cannot solve it, so i need someone help me. |
if current_language[3:5] == str(language)[3:5]: | ||
language_detected = True | ||
#Additional case for Simplified Chinese & Traditional Chinese. | ||
#Traditional Chinese has higher priority |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we need a special case for Simplified and Traditional. In addition I also don't understand why Traditional has higher priority? can you explain this?
Also when doing comments it's good practice to leave a space between the pound (#) and your text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I does not consider the Location of the system when deciding which language to use (so fr_FR and fr_CH will be changed to fr_CA), there will be conflict on the two Chinese language. If I do not do the 'if case', all the Chinese system will choose Traditional Chinese because it lists after the Simplified Chinese in the loop.
About the high priority, it is because that for all the locations that use Chinese, only mainland China uses Simplified Chinese. TW, HK and some South East Asia countries use Traditional Chinese. So I set Traditional Chinese a higher priority and do a special judgement for zh_CN (mainland China).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I think I still don't follow but I'll explain how I understand the auto detection works and you can tell me what makes sense.
As I understand it we're supposed to be auto-detecting the user's OS language that the user set due to line 76 when we call QLocale.system().name(). So if your system Locale is en_US then you get US English, if your locale is en_CA then you should get Canadian English.
When I installed my OS I picked my default language as part of the install process so in my case I'm on en_CA so my locale should always report en_CA for my user (unless I changed it in my user profile). So Freeseer should be getting my correct Locale when it calls QLocale.system().name().
So I would imagine in the case of the Chinese writing systems, I would imagine when the user installed their OS (or by user preferences post install) they would have selected to install Simplified or Traditional Chinese thus the correct zh_CN or zh_HK would already be reported to Freeseer via the Locale variable.
Are you saying we cannot trust the user's OS level Locale setting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably sufficient just to check if the translation file exists (os.path.isfile
) rather than use QDir.
4b4a271
to
4a137f4
Compare
current_language = 'tr_{}.qm'.format(str(QLocale.system().name())) | ||
language_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), | ||
'frontend', 'qtcommon', 'languages', "{}.ts" | ||
.format(current_language.rstrip('.qm'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like you need the .qm
suffix until you return, so it would be better to add it there.
assert detect_system_language() == "tr_{}.qm".format(language) | ||
|
||
def test_detect_system_language_translation_not_found(self, monkeypatch): | ||
'''Tests the detect_system_language methods using negative way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the docstring I provided in the example, it's more descriptive.
So we want
According to the QLocale docs, So now we know we're calling monkeypatch.setattr(QLocale, "name", lambda x: locale) That's it. Here's a full test. def test_detect_system_language_translation_found(self, monkeypatch):
"""Tests detect_system_language() returns the appropriate translation filename for the system language."""
locales = ("ar_EG", "de_DE", "en_US", "fr_CA", "ja", "nl_NL", "sv_SE", "zh_CN", "zh_HK")
for locale in locales:
monkeypatch.setattr(QLocale, "name", lambda x: locale)
assert detect_system_language() == "tr_{}.qm".format(locale) |
@dideler |
0553785
to
6a34cc1
Compare
I found that there are some unit tests fail under Windows. Under Windows I got:
Is that something that needs fix? If yes, I may open an issue about that. |
6a34cc1
to
db93070
Compare
@promm can you show us which 12 tests fail on Windows? Opening an issue is probably best. |
|
||
def test_detect_system_language_translation_found(self, monkeypatch): | ||
"""Tests detect_system_language() returns the appropriate translation filename for the system language.""" | ||
locales = ("ar_EG", "de_DE", "en_US", "fr_CA", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can fit on one line.
db93070
to
2fd1954
Compare
translation = 'tr_{}'.format(QLocale.system().name()) | ||
translation_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'frontend', 'qtcommon', 'languages') | ||
translation_country_language = os.path.join(translation_path, '{}.ts'.format(translation)) | ||
translation_language = os.path.join(translation_path, '{}.ts'.format(translation.split('-')[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be splitting on underscore _
, not dash -
? E.g. tr_en_US
I'm guessing the build on Travis is old since it didn't fail.
Edit: I'm tired and lost, what exactly are you trying to do here? What's the elif case for?
Edit 2: So it looks like locales on Windows use -
while on Linux they use _
. Can you confirm? Also, since ja_JP/ja-JP
is a valid locale, is the if/elif
logic still necessary?
2fd1954
to
7e96e53
Compare
- Freeseer will now scan the System language for the first time. If there is translation for the location, the interface language will be set to that language by default. Otherwise en_US will be used. - Unit test for this function is also added..
7e96e53
to
67f5e40
Compare
@dideler |
Merged as 19c85be, thanks for the contribution. |
If the user does not have the freeseer.conf file, the function will detect the system location for default language.
If there is a config file, the language setting in that file will have higher priority.
For Chinese, If the location is not zh_CN, Traditional Chinese will be used.
If there is no translation for the system location, English will be used.
Fixes #476