MediaArea / MediaInfo

Convenient unified display of the most relevant technical and tag data for video and audio files.
https://MediaArea.net/MediaInfo
BSD 2-Clause "Simplified" License
1.26k stars 149 forks source link

Add translations for Windows GUI theme menu #879

Closed cjee21 closed 1 week ago

cjee21 commented 1 week ago

Since the theme switching menu for dark mode was implemented by me, I thought I should try adding translations for it too. This PR implements translation for the newly added menu items and adds 2 languages as a start so that translators can contribute. Hope I am doing this correctly.

cjee21 commented 1 week ago

Corrected to match Microsoft Terminology.

JeromeMartinez commented 1 week ago

I changed the identifiers in the translation files because "theme" is too much generic and may conflict with something else in the future. I changed the English wording for "system" (using the one from VS). I added the French translation.

Please double-check then pull then force push if you wish to have the "verified" tag on the patch.

cjee21 commented 1 week ago

Should be okay. I'm not good in Mandarin and Korean so someone can correct it in the future if it is not perfect.

cjee21 commented 1 week ago

@JeromeMartinez Tested the latest dev build and encountered a bug: Screenshot 2024-06-21 200401

Steps to reproduce:

  1. Open MediaInfo
  2. Click Language on the menu bar
  3. Select any language including English

Possibly caused by files in %APPDATA%\MediaInfo\Plugin\Language not updated automatically on MediaInfo update? Changing language via the Preferences window works though.

cjee21 commented 1 week ago

Confirm that deleting the entire %APPDATA%\MediaInfo directory fixes the above.

JeromeMartinez commented 1 week ago

It happens sometimes but no clear indication about when, it is not due to your patches, it was the case sometimes in the past too.

cjee21 commented 1 week ago

It happens sometimes but no clear indication about when, it is not due to your patches, it was the case sometimes in the past too.

Very easy to reproduce. Just delete %APPDATA%\MediaInfo\Plugin\Language\en.csv. Now everytime select en in Preferences window or menu drop-down, everything will disappear. However, after close Preferences window it will be back to normal.

This is because there are two copies of translation files. One in C:\Program Files\MediaInfo\Plugin\Language and another in %APPDATA%\MediaInfo\Plugin\Language. The one in %APPDATA% is not updated when MediaInfo is updated so new translations that are updated after the user first install will not be there. It seems MediaInfo use the one in %APPDATA% when changing languages but use the other updated one in other cases.

So at the moment, for updated translations to work properly, user has to manually purge the entire %APPDATA%\MediaInfo after every MediaInfo update. It will then auto generate with latest changes.

JeromeMartinez commented 1 week ago

The one in %APPDATA% is not updated when MediaInfo is updated so new translations that are updated after the user first install will not be there. It seems MediaInfo use the one in %APPDATA% when changing languages but use the other updated one in other cases.

If it is not too much to ask (I am aware that you already done a lot), it would be great if you take some time for fixing that. We are too much late on other things we promised that we can not focus on that now.

%APPDATA%\MediaInfo\Plugin\Language was not wanted, if I remember correctly the copy was more or less done due to access rights after WinXP for templates (the user can edit them in the UI, so it needs to be in a writable dir, but the languages are not) but if it can be avoided it is better.

The one in %APPDATA% is not updated

but a hot fix like updating this one after another install is fine too, and we would work on a better fix... Later.

cjee21 commented 1 week ago

but a hot fix like updating this one after another install is fine too, and we would work on a better fix... Later.

Cannot understand how/why MediaInfo creates copies of the language files and how it decides when to read/write to which folder. All looks very complicated after a quick look.

For a quick/easy workaround, I suggest checking for existence of %APPDATA%\MediaInfo\Plugin\Language on first start-up after version change and if exists, overwrite all the files with ones from install directory. Is this okay? If yes then I'll see if I can implement this.

cjee21 commented 1 week ago

Like this:

https://github.com/MediaArea/MediaInfo/compare/master...cjee21:MediaInfo:translations-fix

    //Load Configuration
    if (Prefs->Config_Load()==2) //Showing options if no config
    {
        #ifndef MEDIAINFOGUI_PREFS_NO
        TPreferencesF* PreferencesF=new TPreferencesF(this);
        PreferencesF->Cancel->Enabled=false;
        PreferencesF->ShowModal();
        delete PreferencesF;
        Prefs->Config_Load(); //Again...
        #endif //MEDIAINFOGUI_PREFS_NO

        //Quick temporary fix for translations after an update
        //----------------------------------------------------------------------------------------------
        //Copies updated language files from install folder to appdata folder if appdata folder exists,
        //overwriting existing files
        //----------------------------------------------------------------------------------------------
        namespace fs = std::filesystem;
        fs::path appdata_path = std::getenv("APPDATA");
        fs::path language_path = appdata_path / "MediaInfo\\Plugin\\Language";
        ZenLib::Ztring BaseFolder;
        BaseFolder=Application->ExeName.c_str();
        fs::path language_source_path = BaseFolder.substr(0, BaseFolder.rfind(__T("\\"))).c_str();
        language_source_path = language_source_path / "Plugin\\Language";
        if (fs::exists(language_path) && fs::is_directory(language_path)) {
            try {
                for (const auto& entry : fs::directory_iterator(language_source_path)) {
                    fs::path current = entry.path();
                    fs::path target = language_path / current.filename();
                    if (fs::is_regular_file(current)) {
                        fs::copy_file(current, target, fs::copy_options::overwrite_existing);
                    }
                }
                //ShowMessage("Success updating translations!");
            } catch (const fs::filesystem_error& e) {
                ShowMessage("Error updating translations in %APPDATA%!");
            }
        }
        //----------------------------------------------------------------------------------------------
    }
JeromeMartinez commented 1 week ago

Cannot understand how/why MediaInfo creates copies of the language files and how it decides when to read/write to which folder.

The template directory in the same top level directory "Plugin" needs to be writable (edit by the program in preferences). 20 years ago, the program files directory was writable. It is no more (for good reasons). There was a quick hack (I don't remember who / when / how) for copying the to level directory "Plugin" from the now read only dir to the writable dir. Duplicate is not necessary, it was not wanted.

All looks very complicated after a quick look.

Reason we always postoned such dev to later, which is not good :(.

For a quick/easy workaround, I suggest checking for existence of %APPDATA%\MediaInfo\Plugin\Language on first start-up after version change and if exists, overwrite all the files with ones from install directory. Is this okay? If yes then I'll see if I can implement this.

Such hot fix is fine for me if it works for new installs (no dir) as well as old installs (existing dir). A better fix could wait.