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

SuperCollider-specific translation files are not loaded on Mac #4619

Closed
claremacrae opened this issue Oct 31, 2019 · 10 comments · Fixed by #4811
Closed

SuperCollider-specific translation files are not loaded on Mac #4619

claremacrae opened this issue Oct 31, 2019 · 10 comments · Fixed by #4811
Assignees
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs.

Comments

@claremacrae
Copy link
Contributor

claremacrae commented Oct 31, 2019

Environment

  • SuperCollider version: revision 069818b checked out
  • Operating system: macOS Mojave 10.14.6
  • Other details (Qt version, audio driver, etc.): Qt 5.13.1, installed vie home-brew

Steps to reproduce

  • Edit editors/sc-ide/translations/scide_fr.ts and change all <translation type="unfinished"></translation> to <translation>sfafdafa</translation>
  • cmake --build . --target install --config RelWithDebInfo
  • Change the default system language to French
  • Reboot
  • Run Install/SuperCollider/SuperCollider.app

Expected vs. actual behavior

Expect behaviour: Most of the UI elements get renamed to sfafdafa
Actual behaviour: No change

@claremacrae claremacrae added the bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. label Oct 31, 2019
@claremacrae
Copy link
Contributor Author

I realise that this is not a real-world problem right now, as all the translation files are empty, but I want to change how the IDE is built, and make sure that I do not make this any worse than it already is, so spent some time tracking down what was going on.

And to capture the things I tried, and learned.

@claremacrae
Copy link
Contributor Author

I added some debug output to main.cpp, to investigate the behaviour of the translation code - and this is what I got:

QLocale::system().name() = en_GB
QLibraryInfo::location(QLibraryInfo::TranslationsPath) = /Users/clare/Documents/develop/Audio/SuperCollider/build/Install/SuperCollider/SuperCollider.app/Contents/translations
ideTranslationPath = /Users/clare/Documents/develop/Audio/SuperCollider/build/Install/SuperCollider/SuperCollider.app/Contents/Resources/translations
QLocale::system().name() = en_GB
QLocale::languageToString( QLocale::system().language() ) = English
QLocale::countryToString( QLocale::system().country() ) = United Kingdom
ideTranslationFile = scide_en_GB

Things that are really weird in this:

  • I have changed the system language to French and rebooted - lots of other applications show a French UI, yet the above output (obtained by double-clicking on the application icon, not launching from the terminal) still shows English
  • The filenames editors/sc-ide/translations/ have 2-character language names, e.g. scide_fr.ts - but QLocale::system().name() is producing 5 chars i.e. en_GB

If I hard-code ideTranslationFile to be scide_fr then my hacked translation file is loaded correctly.

@claremacrae
Copy link
Contributor Author

I think the answer is to change SuperCollider so that it does not identify the translation filename to use, and instead defers to Qt to use the QLocale to search for a range of valid file names.

This overload looks to be what is needed:

https://doc.qt.io/qt-5/qtranslator.html#load-1

bool QTranslator::load(const QLocale &locale, const QString &filename, 
    const QString &prefix = QString(), const QString &directory = QString(), 
    const QString &suffix = QString())

@claremacrae
Copy link
Contributor Author

This looks to be useful example code:

https://github.com/KDAB/GammaRay/blob/master/common/translator.cpp#L53

@claremacrae
Copy link
Contributor Author

Re this overload:

bool QTranslator::load(const QString &filename, const QString &directory = QString(), 
    const QString &search_delimiters = QString(), const QString &suffix = QString())

https://doc.qt.io/qt-5/qtranslator.html#load

It also does some mangling of file names to try and find alternative files... So I wonder whether the only problem is the language coming back as en_GB from the system instead of the fr_FR that I was expecting...

@claremacrae
Copy link
Contributor Author

I am having a look at this... I don't seem to have permission to assign it to myself.

@joshpar
Copy link
Member

joshpar commented Oct 31, 2019

I added us both so I can help if anything comes up.

claremacrae added a commit to claremacrae/supercollider that referenced this issue Oct 31, 2019
…#4619)

The fix is to use the QTranslator::load() overload that takes a
QLocale, instead of searching for the filename ourselves.
That way, Qt's documented logic takes care of finding
scide_fr.qm when the locale contains fr_FR.
@claremacrae
Copy link
Contributor Author

claremacrae commented Oct 31, 2019

I've pushed a fix for this in claremacrae@3668bf9.

In order to set up a test of the change, I did the following:

  1. Create a new translation file, scide_en.ts which was a copy of one of the existing ones
  2. Add that new file to editors/sc-ide/CMakeLists.txt
  3. Copy the text below in to editors/sc-ide/translations/hack_translation.sh
  4. chmod a+x hack_translation.sh and run it
  5. Build the install target, to include all the hacked translations

Then to actually test it, on a Mac:

  1. Change the default Language & Region to French
    • There is no need to reboot the Mac. Just restarting SuperCollider is enough to pick up the new language
  2. Start SuperCollider and confirm that all the menu items and widgets are called scide_fr.ts
  3. Switch language to German, restart SuperCollider, and test that UI contains scide_de.ts
  4. Switch to English, repeat, and test that UI contains scide_en.ts
# Copy in to editors/sc-ide/translations/hack_translation.sh
# This edits each .ts file so that it is obvious which language file was loaded
for file in *.ts ; do
  cat <<EOF > sedscr
s|<translation type="unfinished"></translation>|<translation>$file</translation>|
EOF
  sed -i.bak -f sedscr $file
  rm ${file}.bak
done
rm sedscr

@claremacrae
Copy link
Contributor Author

@joshpar If you feel it's appropriate, please could you review the PR for this - #4620 - and if possible, merge it, as it's a precursor to my making a PR for #4617?

@claremacrae claremacrae changed the title Translation files are not loaded on Mac SuperCollider-specific translation files are not loaded on Mac Nov 3, 2019
@claremacrae
Copy link
Contributor Author

I've picked this up again... Right now, when I create an install on my Mac, there is no translations folder in

build/Install/SuperCollider/SuperCollider.app/Contents/Resources/

This needs debugging before I can reinstate my code to make sure that the translations are found....

claremacrae added a commit to claremacrae/supercollider that referenced this issue Mar 9, 2020
…r#4619).

The code now uses an overload of QTranslator::load()
that does a more thorough job of processing the locale to
find the appropriate translation file.
For more details, see comments in supercollider#4619.
mossheim added a commit that referenced this issue Mar 14, 2020
scide: Fix the finding of locale-specific translations (#4619)
dyfer pushed a commit to dyfer/supercollider that referenced this issue Mar 15, 2020
…r#4619).

The code now uses an overload of QTranslator::load()
that does a more thorough job of processing the locale to
find the appropriate translation file.
For more details, see comments in supercollider#4619.
dvzrv pushed a commit to dvzrv/supercollider that referenced this issue Mar 24, 2020
…r#4619).

The code now uses an overload of QTranslator::load()
that does a more thorough job of processing the locale to
find the appropriate translation file.
For more details, see comments in supercollider#4619.
dvzrv pushed a commit to dvzrv/supercollider that referenced this issue Apr 3, 2020
…r#4619).

The code now uses an overload of QTranslator::load()
that does a more thorough job of processing the locale to
find the appropriate translation file.
For more details, see comments in supercollider#4619.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs.
Projects
None yet
2 participants