-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve tests for extension metadata.
- Loading branch information
Showing
15 changed files
with
207 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"id": "mo2-example-extension", | ||
"name": "Example Extension for UI Base Tests", | ||
"version": "1.0.0", | ||
"description": "ModOrganizer2 example extension for UI Base Tests.", | ||
"author": { | ||
"name": "Mod Organizer 2", | ||
"homepage": "https://www.modorganizer.org/" | ||
}, | ||
"icon": "icon.png", | ||
"contributors": ["AL", "AnyOldName3", "Holt59", "Silarn"], | ||
"type": "plugin", | ||
"translation-context": "mo2-example-extension", | ||
"content": { | ||
"plugins": { | ||
"autodetect": true | ||
}, | ||
"translations": { | ||
"autodetect": "translations" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "test_utils.h" | ||
|
||
#include <QCoreApplication> | ||
|
||
namespace mo2::tests | ||
{ | ||
TranslationHelper::TranslationHelper() {} | ||
|
||
TranslationHelper::~TranslationHelper() | ||
{ | ||
release(); | ||
} | ||
|
||
void TranslationHelper::release() | ||
{ | ||
if (m_Translator) { | ||
QCoreApplication::removeTranslator(m_Translator.get()); | ||
m_Translator.reset(); | ||
} | ||
} | ||
|
||
void TranslationHelper::switchLanguage(const QString& lang) | ||
{ | ||
m_Translator = std::make_unique<QTranslator>(); | ||
if (m_Translator->load("tests_" + lang, "tests/translations")) { | ||
QCoreApplication::installTranslator(m_Translator.get()); | ||
} else { | ||
m_Translator.reset(); | ||
} | ||
} | ||
} // namespace mo2::tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include <QString> | ||
#include <QTranslator> | ||
|
||
namespace mo2::tests | ||
{ | ||
|
||
class TranslationHelper | ||
{ | ||
public: | ||
// create a new translation helper that can be used to switch language during tests | ||
TranslationHelper(); | ||
~TranslationHelper(); | ||
|
||
// switch to the given language (should be available) | ||
void switchLanguage(const QString& lang); | ||
|
||
private: | ||
std::unique_ptr<QTranslator> m_Translator; | ||
|
||
void release(); | ||
}; | ||
|
||
} // namespace mo2::tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
from PyQt6.lupdate.source_file import SourceFile | ||
from PyQt6.lupdate.translation_file import TranslationFile | ||
from PyQt6.lupdate.translations import Context, Message | ||
|
||
folder = Path(__file__).parent | ||
|
||
tr_files = [ | ||
TranslationFile(path, no_obsolete=False, no_summary=False, verbose=True) | ||
for path in folder.glob("*.ts") | ||
] | ||
|
||
for metadata_path in folder.parent.joinpath("data", "extensions").glob("**/*.json"): | ||
with open(metadata_path, "rb") as fp: | ||
metadata = json.load(fp) | ||
|
||
if "translation-context" not in metadata: | ||
continue | ||
|
||
source = SourceFile(filename=metadata_path) | ||
|
||
context = Context(name=metadata["translation-context"]) | ||
|
||
for key in ("name", "description"): | ||
if key not in metadata: | ||
continue | ||
|
||
context.messages.append( | ||
Message( | ||
filename=metadata_path, | ||
line_nr=-1, | ||
source=metadata[key], | ||
comment=None, | ||
numerus=None, | ||
) | ||
) | ||
|
||
source.contexts.append(context) | ||
|
||
for tr_file in tr_files: | ||
tr_file.update(source) | ||
|
||
for tr_file in tr_files: | ||
tr_file.write() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!DOCTYPE TS> | ||
<TS version="2.1" language="en_US"> | ||
<context> | ||
<name>mo2-example-extension</name> | ||
<message> | ||
<location filename="../data/extensions/mo2-example-extension/metadata.json"/> | ||
<source>Example Extension for UI Base Tests</source> | ||
<translation></translation> | ||
</message> | ||
<message> | ||
<location line="-2"/> | ||
<source>ModOrganizer2 example extension for UI Base Tests.</source> | ||
<translation></translation> | ||
</message> | ||
</context> | ||
<context> | ||
<name>uibase-tests</name> | ||
<message> | ||
<source>Translate to French</source> | ||
<translation>Translate to French</translation> | ||
<translation type="vanished">Translate to French</translation> | ||
</message> | ||
</context> | ||
</TS> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!DOCTYPE TS> | ||
<TS version="2.1" language="fr_FR"> | ||
<context> | ||
<name>mo2-example-extension</name> | ||
<message> | ||
<location filename="../data/extensions/mo2-example-extension/metadata.json"/> | ||
<source>Example Extension for UI Base Tests</source> | ||
<translation>Extension Démo pour les tests UI Base</translation> | ||
</message> | ||
<message> | ||
<location line="-2"/> | ||
<source>ModOrganizer2 example extension for UI Base Tests.</source> | ||
<translation type="unfinished">Exemple d'extension ModOrganizer2 pour les tests UI Base.</translation> | ||
</message> | ||
</context> | ||
<context> | ||
<name>uibase-tests</name> | ||
<message> | ||
<source>Translate to French</source> | ||
<translation>Traduction en Français</translation> | ||
<translation type="vanished">Traduction en Français</translation> | ||
</message> | ||
</context> | ||
</TS> |