Added option to load translations from an "external" file, for easier translation testing.

This commit is contained in:
LoRd_MuldeR 2011-01-06 00:53:52 +01:00
parent 8903bb4f03
commit bb538580d6
10 changed files with 116 additions and 19 deletions

View File

@ -14,7 +14,7 @@
<br>
<h3>Editing the language file:</h3>
<p>LameXP v4.xx translations are created as TS (translation) files, which can be edited using the <i>Qt Linguist</i> application. For new translations an empty TS file ("Blank.ts") is provided in the LameXP Git repository. When you open the empty TS file for the first time, Linguist will ask for some basic settings. Here you must keep the "Source language" options at "English" and "Any Country". Change the "Target language" options to whatever language (region) you are going to translate too. Once you have edited all (or some) text strings, you can save your work to a TS file again. It is recommended to save your work to "LameXP_XX.ts", where <i>XX</i> should be replaced with the suitable upper-case <a href="http://www.loc.gov/standards/iso639-2/php/code_list.php" target="_blank">ISO 639-1</a> country code (for example the German translation is saved as "LameXP_DE.ts"). You can re-open your TS file at any time in order to continue with your work. In case you want to improve an existing LameXP translation, simply download the corresponding TS file from the LameXP Git repository and edit it using the Qt Linguist tool.</p>
<p>The latest translation (TS) files can always be found in the LameXP Git repository at:<br><a href="https://github.com/lordmulder/LameXP/tree/master/etc/Translation" target="_blank">https://github.com/lordmulder/LameXP/tree/master/etc/Translation</a></p>
<p>The latest translation (TS) files can always be found in the LameXP Git repository at:<br><a href="https://github.com/lordmulder/LameXP/tree/master/etc/Translation" target="_blank">https://github.com/lordmulder/LameXP/tree/master/etc/Translation</a><br>(After you have chosen a file from the directory tree, you can download the file by right-clicking on "raw" an choosing "Save Link Target As...")</p>
<p><font color="darkred"><b>Important:</b> Before you start translating, always make sure your download the <i>latest</i> "Blank.ts" file from the LameXP Git repository. If you want to edit an existing translation, including translations you have created yourself, make sure your download the <i>latest</i> TS file from the LameXP Git repository. Never ever do any translations based on an old working copy (TS file) from your local system! The translation files in the repository will be updated, as the development proceeds.</font></p>
<br>
<h3>Language file editing rules:</h3>

View File

@ -462,6 +462,10 @@
<source>Show DropBox</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>From File...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Adding file(s), please wait...</source>
<translation type="unfinished"></translation>
@ -674,6 +678,14 @@
<source>Add folder</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Load Translation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Translation Files</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>New Folder</source>
<translation type="unfinished"></translation>

View File

@ -831,6 +831,18 @@
<source>No</source>
<translation>Nein</translation>
</message>
<message>
<source>From File...</source>
<translation>Von Datei...</translation>
</message>
<message>
<source>Load Translation</source>
<translation>Übersetzung Laden</translation>
</message>
<message>
<source>Translation Files</source>
<translation>Übersetzungsdateien</translation>
</message>
</context>
<context>
<name>MetaInfo</name>

View File

@ -1229,6 +1229,7 @@
<iconset resource="../res/Icons.qrc">
<normaloff>:/icons/font.png</normaloff>:/icons/font.png</iconset>
</property>
<addaction name="actionLoadTranslationFromFile"/>
</widget>
<addaction name="actionSourceFiles"/>
<addaction name="actionOutputDirectory"/>
@ -1476,6 +1477,15 @@
<string notr="true">English</string>
</property>
</action>
<action name="actionLoadTranslationFromFile">
<property name="icon">
<iconset resource="../res/Icons.qrc">
<normaloff>:/icons/folder_page.png</normaloff>:/icons/folder_page.png</iconset>
</property>
<property name="text">
<string>From File...</string>
</property>
</action>
</widget>
<resources>
<include location="../res/Icons.qrc"/>
@ -1489,6 +1499,10 @@
<include location="../res/Images.qrc"/>
<include location="../res/Icons.qrc"/>
<include location="../res/Images.qrc"/>
<include location="../res/Icons.qrc"/>
<include location="../res/Images.qrc"/>
<include location="../res/Icons.qrc"/>
<include location="../res/Images.qrc"/>
</resources>
<connections>
<connection>

Binary file not shown.

View File

@ -25,7 +25,7 @@
#define VER_LAMEXP_MAJOR 4
#define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 0
#define VER_LAMEXP_BUILD 217
#define VER_LAMEXP_BUILD 218
#define VER_LAMEXP_SUFFIX TechPreview
/*

View File

@ -250,19 +250,21 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
//Populate the language menu
m_languageActionGroup = new QActionGroup(this);
connect(m_languageActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(languageActionActivated(QAction*)));
QStringList translations = lamexp_query_translations();
while(!translations.isEmpty())
{
QString langId = translations.takeFirst();
QString langId = translations.takeLast();
QAction *currentLanguage = new QAction(this);
currentLanguage->setData(langId);
currentLanguage->setText(lamexp_translation_name(langId));
currentLanguage->setIcon(QIcon(QString(":/flags/%1.png").arg(langId)));
currentLanguage->setCheckable(true);
m_languageActionGroup->addAction(currentLanguage);
menuLanguage->addAction(currentLanguage);
menuLanguage->insertAction(actionLoadTranslationFromFile, currentLanguage);
}
menuLanguage->insertSeparator(actionLoadTranslationFromFile);
connect(actionLoadTranslationFromFile, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
connect(m_languageActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(languageActionActivated(QAction*)));
//Activate tools menu actions
actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled());
@ -1038,14 +1040,45 @@ void MainWindow::styleActionActivated(QAction *action)
* Language action triggered
*/
void MainWindow::languageActionActivated(QAction *action)
{
if(action->data().type() == QVariant::String)
{
QString langId = action->data().toString();
if(lamexp_install_translator(langId))
{
action->setChecked(true);
m_settings->currentLanguage(langId);
}
}
}
/*
* Load language from file action triggered
*/
void MainWindow::languageFromFileActionActivated(bool checked)
{
QFileDialog dialog(this, tr("Load Translation"));
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
if(dialog.exec())
{
QStringList selectedFiles = dialog.selectedFiles();
if(lamexp_install_translator_from_file(selectedFiles.first()))
{
QList<QAction*> actions = m_languageActionGroup->actions();
while(!actions.isEmpty())
{
actions.takeFirst()->setChecked(false);
}
}
else
{
languageActionActivated(m_languageActionGroup->actions().first());
}
}
}
/*
* Output folder changed (mouse clicked)

View File

@ -61,6 +61,7 @@ private slots:
void tabActionActivated(QAction *action);
void styleActionActivated(QAction *action);
void languageActionActivated(QAction *action);
void languageFromFileActionActivated(bool checked);
void outputFolderViewClicked(const QModelIndex &index);
void outputFolderViewMoved(const QModelIndex &index);
void makeFolderButtonClicked(void);

View File

@ -917,24 +917,16 @@ bool lamexp_install_translator(const QString &langId)
{
bool success = false;
if(!g_lamexp_currentTranslator)
{
g_lamexp_currentTranslator = new QTranslator();
}
if(langId.isEmpty() || langId.toLower().compare(LAMEXP_DEFAULT_LANGID) == 0)
{
QApplication::removeTranslator(g_lamexp_currentTranslator);
success = true;
success = lamexp_install_translator_from_file(QString());
}
else
{
QString qmFile = g_lamexp_translation_files.value(langId.toLower(), QString());
if(!qmFile.isEmpty())
{
QApplication::removeTranslator(g_lamexp_currentTranslator);
success = g_lamexp_currentTranslator->load(QString(":/localization/%1").arg(qmFile));
QApplication::installTranslator(g_lamexp_currentTranslator);
success = lamexp_install_translator_from_file(QString(":/localization/%1").arg(qmFile));
}
else
{
@ -945,6 +937,38 @@ bool lamexp_install_translator(const QString &langId)
return success;
}
/*
* Install a new translator from file
*/
bool lamexp_install_translator_from_file(const QString &qmFile)
{
bool success = false;
if(!g_lamexp_currentTranslator)
{
g_lamexp_currentTranslator = new QTranslator();
}
if(!qmFile.isEmpty())
{
QString qmPath = QFileInfo(qmFile).canonicalFilePath();
QApplication::removeTranslator(g_lamexp_currentTranslator);
success = g_lamexp_currentTranslator->load(qmPath);
QApplication::installTranslator(g_lamexp_currentTranslator);
if(!success)
{
qWarning("Failed to load translation:\n\"%s\"", qmPath.toLatin1().constData());
}
}
else
{
QApplication::removeTranslator(g_lamexp_currentTranslator);
success = true;
}
return success;
}
/*
* Locate known folder on local system
*/

View File

@ -97,6 +97,7 @@ QStringList lamexp_query_translations(void);
bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId);
QString lamexp_translation_name(const QString &language);
unsigned int lamexp_translation_sysid(const QString &langId);
bool lamexp_install_translator_from_file(const QString &qmFile);
bool lamexp_install_translator(const QString &language);
static const char* LAMEXP_DEFAULT_LANGID = "en";