<commit_before>/***************************************************************************
 *   Copyright (c) 2004 <NAME> <wmayer[at]users.sourceforge.net>     *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 of the License, or (at your option) any later version.      *
 *                                                                         *
 *   This library  is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/


#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <QTranslator>
# include <QStringList>
# include <QDir>
# include <QApplication>
#endif

#include "Translator.h"
#include <App/Application.h>

using namespace Gui;

/** \defgroup i18n Internationalization with FreeCAD
 *  \ingroup GUI
 *
 * The internationalization of FreeCAD makes heavy use of the internationalization
 * support of Qt. For more details refer to your Qt documentation.
 * 
 * \section stepbystep Step by step
 * To integrate a new language into FreeCAD or one of its application modules
 * you have to perform the following steps:
 *
 * \subsection tsfile Creation of a .ts file
 * First you have to generate a .ts file for the language to be translated. You can do this
 * by running the \a lupdate tool in the \a bin path of your Qt installation. As argument
 * you can specify either all related source files and the .ts output file or a Qt project 
 * file (.pro) which contains all relevant source files.
 *
 * \subsection translate Translation into your language
 * To translate the english string literals into the language you want to support you can open your
 * .ts file with \a QtLinguist and translate all literals by hand. Another way
 * for translation is to use the tool \a tsauto from <NAME>.This tool uses the 
 * engine from Google web page (www.google.com). tsauto supports the languages
 * \li english
 * \li french
 * \li german
 * \li italian
 * \li portuguese and
 * \li spanish
 *
 * \remark To get most of the literals translated you should have removed all
 * special characters (like &, !, ?, ...). Otherwise the translation could fail.
 * After having translated all literals you can load the .ts file into QtLinguist and 
 * invoke the menu item \a Release which generates the binary .qm file.
 *
 * \subsection usets Integration of the .qm file
 * The .qm file should now be integrated into the GUI library (either of FreeCAD
 * itself or its application module). The .qm file will be embedded into the
 * resulting binary file. So, at runtime you don't need any .qm files any
 * more. Indeed you will have a bigger binary file but you haven't any troubles
 * concerning missing .qm files.
 *
 * To integrate the .qm file into the executable you have to create a resource file (.qrc), first.
 * This is an XML file where you can append the .qm file. For the .qrc file you have to define the following
 * curstom build step inside the Visual Studio project file:
 *
 * Command Line: rcc.exe -name $(InputName) $(InputPath) -o "$(InputDir)qrc_$(InputName).cpp"
 * Outputs:      $(InputDir)qrc_$(InputName).cpp
 * 
 * For the gcc build system you just have to add the line \<resourcefile\>.qrc to the BUILT_SOURCES
 * sources section of the Makefile.am, run automake and configure (or ./confog.status) afterwards.
 *
 * Finally, you have to add a the line
 * \code
 * 
 * Q_INIT_RESOURCE(resource);
 *
 * \endcode
 * 
 * where \a resource is the name of the .qrc file. That's all!
 */

/* TRANSLATOR Gui::Translator */

Translator* Translator::_pcSingleton = 0;

namespace Gui {
class TranslatorP
{
public:
    std::string activatedLanguage; /**< Active language */
    std::map<std::string, std::string> mapLanguageTopLevelDomain;
    std::list<QTranslator*> translators; /**< A list of all created translators */
    QStringList paths;
};
}

Translator* Translator::instance(void)
{
    if (!_pcSingleton)
        _pcSingleton = new Translator;
    return _pcSingleton;
}

void Translator::destruct (void)
{
    if (_pcSingleton)
        delete _pcSingleton;
    _pcSingleton=0;
}

Translator::Translator()
{
    // This is needed for Qt's lupdate
    d = new TranslatorP;
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("English"              )] = "en";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("German"               )] = "de";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Spanish"              )] = "es-ES";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("French"               )] = "fr";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Italian"              )] = "it";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Japanese"             )] = "ja";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Chinese Simplified"   )] = "zh-CN";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Chinese Traditional"  )] = "zh-TW";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Korean"               )] = "kr";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Russian"              )] = "ru";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Swedish"              )] = "sv-SE";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Afrikaans"            )] = "af";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Norwegian"            )] = "no";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Portuguese, Brazilian")] = "pt-BR";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Portuguese"           )] = "pt-PT";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Dutch"                )] = "nl";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Ukrainian"            )] = "uk";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Finnish"              )] = "fi";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Croatian"             )] = "hr";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Polish"               )] = "pl";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Czech"                )] = "cs";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Hungarian"            )] = "hu";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Romanian"             )] = "ro";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Slovak"               )] = "sk";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Turkish"              )] = "tr";
    d->activatedLanguage = "English";

    d->paths = directories();
}

Translator::~Translator()
{
    removeTranslators();
    delete d;
}

TStringList Translator::supportedLanguages() const
{
    // List all .qm files
    TStringList languages;<commit_msg>+ Fix suffix for Korean<commit_after>/***************************************************************************
 *   Copyright (c) 2004 <NAME> <wmayer[at]users.sourceforge.net>     *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 of the License, or (at your option) any later version.      *
 *                                                                         *
 *   This library  is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/


#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <QTranslator>
# include <QStringList>
# include <QDir>
# include <QApplication>
#endif

#include "Translator.h"
#include <App/Application.h>

using namespace Gui;

/** \defgroup i18n Internationalization with FreeCAD
 *  \ingroup GUI
 *
 * The internationalization of FreeCAD makes heavy use of the internationalization
 * support of Qt. For more details refer to your Qt documentation.
 * 
 * \section stepbystep Step by step
 * To integrate a new language into FreeCAD or one of its application modules
 * you have to perform the following steps:
 *
 * \subsection tsfile Creation of a .ts file
 * First you have to generate a .ts file for the language to be translated. You can do this
 * by running the \a lupdate tool in the \a bin path of your Qt installation. As argument
 * you can specify either all related source files and the .ts output file or a Qt project 
 * file (.pro) which contains all relevant source files.
 *
 * \subsection translate Translation into your language
 * To translate the english string literals into the language you want to support you can open your
 * .ts file with \a QtLinguist and translate all literals by hand. Another way
 * for translation is to use the tool \a tsauto from <NAME>.This tool uses the 
 * engine from Google web page (www.google.com). tsauto supports the languages
 * \li english
 * \li french
 * \li german
 * \li italian
 * \li portuguese and
 * \li spanish
 *
 * \remark To get most of the literals translated you should have removed all
 * special characters (like &, !, ?, ...). Otherwise the translation could fail.
 * After having translated all literals you can load the .ts file into QtLinguist and 
 * invoke the menu item \a Release which generates the binary .qm file.
 *
 * \subsection usets Integration of the .qm file
 * The .qm file should now be integrated into the GUI library (either of FreeCAD
 * itself or its application module). The .qm file will be embedded into the
 * resulting binary file. So, at runtime you don't need any .qm files any
 * more. Indeed you will have a bigger binary file but you haven't any troubles
 * concerning missing .qm files.
 *
 * To integrate the .qm file into the executable you have to create a resource file (.qrc), first.
 * This is an XML file where you can append the .qm file. For the .qrc file you have to define the following
 * curstom build step inside the Visual Studio project file:
 *
 * Command Line: rcc.exe -name $(InputName) $(InputPath) -o "$(InputDir)qrc_$(InputName).cpp"
 * Outputs:      $(InputDir)qrc_$(InputName).cpp
 * 
 * For the gcc build system you just have to add the line \<resourcefile\>.qrc to the BUILT_SOURCES
 * sources section of the Makefile.am, run automake and configure (or ./confog.status) afterwards.
 *
 * Finally, you have to add a the line
 * \code
 * 
 * Q_INIT_RESOURCE(resource);
 *
 * \endcode
 * 
 * where \a resource is the name of the .qrc file. That's all!
 */

/* TRANSLATOR Gui::Translator */

Translator* Translator::_pcSingleton = 0;

namespace Gui {
class TranslatorP
{
public:
    std::string activatedLanguage; /**< Active language */
    std::map<std::string, std::string> mapLanguageTopLevelDomain;
    std::list<QTranslator*> translators; /**< A list of all created translators */
    QStringList paths;
};
}

Translator* Translator::instance(void)
{
    if (!_pcSingleton)
        _pcSingleton = new Translator;
    return _pcSingleton;
}

void Translator::destruct (void)
{
    if (_pcSingleton)
        delete _pcSingleton;
    _pcSingleton=0;
}

Translator::Translator()
{
    // This is needed for Qt's lupdate
    d = new TranslatorP;
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("English"              )] = "en";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("German"               )] = "de";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Spanish"              )] = "es-ES";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("French"               )] = "fr";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Italian"              )] = "it";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Japanese"             )] = "ja";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Chinese Simplified"   )] = "zh-CN";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Chinese Traditional"  )] = "zh-TW";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Korean"               )] = "ko";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Russian"              )] = "ru";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Swedish"              )] = "sv-SE";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Afrikaans"            )] = "af";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Norwegian"            )] = "no";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Portuguese, Brazilian")] = "pt-BR";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Portuguese"           )] = "pt-PT";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Dutch"                )] = "nl";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Ukrainian"            )] = "uk";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Finnish"              )] = "fi";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Croatian"             )] = "hr";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Polish"               )] = "pl";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Czech"                )] = "cs";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Hungarian"            )] = "hu";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Romanian"             )] = "ro";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Slovak"               )] = "sk";
    d->mapLanguageTopLevelDomain[QT_TR_NOOP("Turkish"              )] = "tr";
    d->activatedLanguage = "English";

    d->paths = directories();
}

Translator::~Translator()
{
    removeTranslators();
    delete d;
}

TStringList Translator::supportedLanguages() const
{
    // List all .qm files
    TStringList languages;
{'fraction_non_alphanumeric': 0.1157358390682901, 'fraction_numerical': 0.0030439385918475384, 'mean_word_length': 2.583827365425658, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4646147', 'n_tokens_mistral': 4445, 'n_tokens_neox': 4149, 'n_words': 1395}