File indexing completed on 2024-04-14 03:43:54

0001 /*
0002     SPDX-FileCopyrightText: 2003-2006 Cies Breijs <cies AT kde DOT nl>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "translator.h"
0008 
0009 #include <KLocalizedString>
0010 #include <QRegExp>
0011 #include "token.h"
0012 
0013 
0014 Translator* Translator::m_instance = nullptr;  // initialize pointer
0015 
0016 Translator* Translator::instance()
0017 {
0018     if (m_instance == nullptr) m_instance = new Translator;  // create sole instance if its the first call
0019     return m_instance;  // address of sole instance
0020 }
0021 
0022 Translator::Translator()
0023     : localizer(QStringList() << QLatin1String(DEFAULT_LANGUAGE_CODE))
0024 {
0025 }
0026 
0027 Translator::~Translator()
0028 {
0029     delete m_instance;
0030     m_instance = nullptr;
0031 }
0032 
0033 
0034 int Translator::look2type(QString& look)
0035 {
0036     if (look2typeMap.contains(look))
0037         return look2typeMap[look];
0038     return Token::Unknown;
0039 }
0040 
0041 int Translator::look2type(QChar& look)
0042 {
0043     if (look2typeMap.contains(static_cast<QString>(look)))
0044         return look2typeMap[static_cast<QString>(look)];
0045     return Token::Unknown;
0046 }
0047 
0048 QList<QString> Translator::type2look(int type)
0049 {
0050     return look2typeMap.keys(type);
0051 }
0052 
0053 QHash<int, QList<QString> > Translator::token2stringsMap()
0054 {
0055     QHash<int, QList<QString> > resultMap;
0056     const QList<int> tokenList = look2typeMap.values();
0057     for (int token : tokenList) resultMap.insert(token, look2typeMap.keys(token));
0058     return resultMap;
0059 }
0060 
0061 
0062 bool Translator::setLanguage(const QString &lang_code)
0063 {
0064     // FIXME default to GUI language? return false when language not available?
0065     localizer = QStringList() << lang_code << QLatin1String(DEFAULT_LANGUAGE_CODE);
0066 
0067     setDictionary();
0068     setExamples();
0069 
0070     return true;
0071 }
0072 
0073 
0074 void Translator::setDictionary()
0075 {
0076     look2typeMap.clear();
0077     default2localizedMap.clear();
0078 
0079     QString localizedCommandLook;
0080 
0081 
0082 //BEGIN GENERATED translator_cpp CODE
0083 
0084 /* The code between the line that start with "//BEGIN GENERATED" and "//END GENERATED"
0085  * is generated by "generate.rb" according to the definitions specified in
0086  * "definitions.rb". Please make all changes in the "definitions.rb" file, since all
0087  * all change you make here will be overwritten the next time "generate.rb" is run.
0088  * Thanks for looking at the code!
0089  */
0090 
0091     look2typeMap[QStringLiteral("$")] = Token::VariablePrefix;
0092 
0093     localizedCommandLook = ki18nc(
0094         "You are about to translate the 'True' COMMAND, there are some rules on how to translate it."
0095         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0096         "true").toString(localizer);
0097     default2localizedMap[QStringLiteral("true")] = localizedCommandLook;
0098     look2typeMap[localizedCommandLook] = Token::True;
0099 
0100     localizedCommandLook = ki18nc(
0101         "You are about to translate the 'False' COMMAND, there are some rules on how to translate it."
0102         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0103         "false").toString(localizer);
0104     default2localizedMap[QStringLiteral("false")] = localizedCommandLook;
0105     look2typeMap[localizedCommandLook] = Token::False;
0106 
0107     look2typeMap[QStringLiteral("#")] = Token::Comment;
0108 
0109     look2typeMap[QStringLiteral("\"")] = Token::StringDelimiter;
0110 
0111     look2typeMap[QStringLiteral("{")] = Token::ScopeOpen;
0112 
0113     look2typeMap[QStringLiteral("}")] = Token::ScopeClose;
0114 
0115     look2typeMap[QStringLiteral("(")] = Token::ParenthesisOpen;
0116 
0117     look2typeMap[QStringLiteral(")")] = Token::ParenthesisClose;
0118 
0119     localizedCommandLook = ki18nc(
0120         "You are about to translate the 'ArgumentSeparator' COMMAND, there are some rules on how to translate it."
0121         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0122         ",").toString(localizer);
0123     default2localizedMap[QStringLiteral(",")] = localizedCommandLook;
0124     look2typeMap[localizedCommandLook] = Token::ArgumentSeparator;
0125 
0126     localizedCommandLook = ki18nc(
0127         "You are about to translate the 'DecimalSeparator' COMMAND, there are some rules on how to translate it."
0128         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0129         ".").toString(localizer);
0130     default2localizedMap[QStringLiteral(".")] = localizedCommandLook;
0131     look2typeMap[localizedCommandLook] = Token::DecimalSeparator;
0132 
0133     localizedCommandLook = ki18nc(
0134         "You are about to translate the 'Exit' COMMAND, there are some rules on how to translate it."
0135         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0136         "exit").toString(localizer);
0137     default2localizedMap[QStringLiteral("exit")] = localizedCommandLook;
0138     look2typeMap[localizedCommandLook] = Token::Exit;
0139 
0140     localizedCommandLook = ki18nc(
0141         "You are about to translate the 'If' COMMAND, there are some rules on how to translate it."
0142         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0143         "if").toString(localizer);
0144     default2localizedMap[QStringLiteral("if")] = localizedCommandLook;
0145     look2typeMap[localizedCommandLook] = Token::If;
0146 
0147     localizedCommandLook = ki18nc(
0148         "You are about to translate the 'Else' COMMAND, there are some rules on how to translate it."
0149         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0150         "else").toString(localizer);
0151     default2localizedMap[QStringLiteral("else")] = localizedCommandLook;
0152     look2typeMap[localizedCommandLook] = Token::Else;
0153 
0154     localizedCommandLook = ki18nc(
0155         "You are about to translate the 'Repeat' COMMAND, there are some rules on how to translate it."
0156         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0157         "repeat").toString(localizer);
0158     default2localizedMap[QStringLiteral("repeat")] = localizedCommandLook;
0159     look2typeMap[localizedCommandLook] = Token::Repeat;
0160 
0161     localizedCommandLook = ki18nc(
0162         "You are about to translate the 'While' COMMAND, there are some rules on how to translate it."
0163         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0164         "while").toString(localizer);
0165     default2localizedMap[QStringLiteral("while")] = localizedCommandLook;
0166     look2typeMap[localizedCommandLook] = Token::While;
0167 
0168     localizedCommandLook = ki18nc(
0169         "You are about to translate the 'For' COMMAND, there are some rules on how to translate it."
0170         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0171         "for").toString(localizer);
0172     default2localizedMap[QStringLiteral("for")] = localizedCommandLook;
0173     look2typeMap[localizedCommandLook] = Token::For;
0174 
0175     localizedCommandLook = ki18nc(
0176         "You are about to translate the 'To' COMMAND, there are some rules on how to translate it."
0177         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0178         "to").toString(localizer);
0179     default2localizedMap[QStringLiteral("to")] = localizedCommandLook;
0180     look2typeMap[localizedCommandLook] = Token::To;
0181 
0182     localizedCommandLook = ki18nc(
0183         "You are about to translate the 'Step' COMMAND, there are some rules on how to translate it."
0184         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0185         "step").toString(localizer);
0186     default2localizedMap[QStringLiteral("step")] = localizedCommandLook;
0187     look2typeMap[localizedCommandLook] = Token::Step;
0188 
0189     localizedCommandLook = ki18nc(
0190         "You are about to translate the 'Break' COMMAND, there are some rules on how to translate it."
0191         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0192         "break").toString(localizer);
0193     default2localizedMap[QStringLiteral("break")] = localizedCommandLook;
0194     look2typeMap[localizedCommandLook] = Token::Break;
0195 
0196     localizedCommandLook = ki18nc(
0197         "You are about to translate the 'Return' COMMAND, there are some rules on how to translate it."
0198         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0199         "return").toString(localizer);
0200     default2localizedMap[QStringLiteral("return")] = localizedCommandLook;
0201     look2typeMap[localizedCommandLook] = Token::Return;
0202 
0203     localizedCommandLook = ki18nc(
0204         "You are about to translate the 'Wait' COMMAND, there are some rules on how to translate it."
0205         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0206         "wait").toString(localizer);
0207     default2localizedMap[QStringLiteral("wait")] = localizedCommandLook;
0208     look2typeMap[localizedCommandLook] = Token::Wait;
0209 
0210     localizedCommandLook = ki18nc(
0211         "You are about to translate the 'Assert' COMMAND, there are some rules on how to translate it."
0212         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0213         "assert").toString(localizer);
0214     default2localizedMap[QStringLiteral("assert")] = localizedCommandLook;
0215     look2typeMap[localizedCommandLook] = Token::Assert;
0216 
0217     localizedCommandLook = ki18nc(
0218         "You are about to translate the 'And' COMMAND, there are some rules on how to translate it."
0219         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0220         "and").toString(localizer);
0221     default2localizedMap[QStringLiteral("and")] = localizedCommandLook;
0222     look2typeMap[localizedCommandLook] = Token::And;
0223 
0224     localizedCommandLook = ki18nc(
0225         "You are about to translate the 'Or' COMMAND, there are some rules on how to translate it."
0226         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0227         "or").toString(localizer);
0228     default2localizedMap[QStringLiteral("or")] = localizedCommandLook;
0229     look2typeMap[localizedCommandLook] = Token::Or;
0230 
0231     localizedCommandLook = ki18nc(
0232         "You are about to translate the 'Not' COMMAND, there are some rules on how to translate it."
0233         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0234         "not").toString(localizer);
0235     default2localizedMap[QStringLiteral("not")] = localizedCommandLook;
0236     look2typeMap[localizedCommandLook] = Token::Not;
0237 
0238     look2typeMap[QStringLiteral("==")] = Token::Equals;
0239 
0240     look2typeMap[QStringLiteral("!=")] = Token::NotEquals;
0241 
0242     look2typeMap[QStringLiteral(">")] = Token::GreaterThan;
0243 
0244     look2typeMap[QStringLiteral("<")] = Token::LessThan;
0245 
0246     look2typeMap[QStringLiteral(">=")] = Token::GreaterOrEquals;
0247 
0248     look2typeMap[QStringLiteral("<=")] = Token::LessOrEquals;
0249 
0250     look2typeMap[QStringLiteral("+")] = Token::Addition;
0251 
0252     look2typeMap[QStringLiteral("-")] = Token::Subtraction;
0253 
0254     look2typeMap[QStringLiteral("*")] = Token::Multiplication;
0255 
0256     look2typeMap[QStringLiteral("/")] = Token::Division;
0257 
0258     look2typeMap[QStringLiteral("^")] = Token::Power;
0259 
0260     look2typeMap[QStringLiteral("=")] = Token::Assign;
0261 
0262     localizedCommandLook = ki18nc(
0263         "You are about to translate the 'Learn' COMMAND, there are some rules on how to translate it."
0264         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0265         "learn").toString(localizer);
0266     default2localizedMap[QStringLiteral("learn")] = localizedCommandLook;
0267     look2typeMap[localizedCommandLook] = Token::Learn;
0268 
0269     localizedCommandLook = ki18nc(
0270         "You are about to translate the 'Reset' COMMAND, there are some rules on how to translate it."
0271         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0272         "reset").toString(localizer);
0273     default2localizedMap[QStringLiteral("reset")] = localizedCommandLook;
0274     look2typeMap[localizedCommandLook] = Token::Reset;
0275 
0276     localizedCommandLook = ki18nc(
0277         "You are about to translate the 'Clear' COMMAND, there are some rules on how to translate it."
0278         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0279         "clear").toString(localizer);
0280     default2localizedMap[QStringLiteral("clear")] = localizedCommandLook;
0281     look2typeMap[localizedCommandLook] = Token::Clear;
0282 
0283     localizedCommandLook = ki18nc(
0284         "You are about to translate the 'Clear' COMMAND ALIAS, there are some rules on how to translate it."
0285         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0286         "ccl").toString(localizer);
0287     default2localizedMap[QStringLiteral("ccl")] = localizedCommandLook;
0288     look2typeMap[localizedCommandLook] = Token::Clear;
0289 
0290     localizedCommandLook = ki18nc(
0291         "You are about to translate the 'Center' COMMAND, there are some rules on how to translate it."
0292         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0293         "center").toString(localizer);
0294     default2localizedMap[QStringLiteral("center")] = localizedCommandLook;
0295     look2typeMap[localizedCommandLook] = Token::Center;
0296 
0297     localizedCommandLook = ki18nc(
0298         "You are about to translate the 'Go' COMMAND, there are some rules on how to translate it."
0299         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0300         "go").toString(localizer);
0301     default2localizedMap[QStringLiteral("go")] = localizedCommandLook;
0302     look2typeMap[localizedCommandLook] = Token::Go;
0303 
0304     localizedCommandLook = ki18nc(
0305         "You are about to translate the 'GoX' COMMAND, there are some rules on how to translate it."
0306         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0307         "gox").toString(localizer);
0308     default2localizedMap[QStringLiteral("gox")] = localizedCommandLook;
0309     look2typeMap[localizedCommandLook] = Token::GoX;
0310 
0311     localizedCommandLook = ki18nc(
0312         "You are about to translate the 'GoX' COMMAND ALIAS, there are some rules on how to translate it."
0313         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0314         "gx").toString(localizer);
0315     default2localizedMap[QStringLiteral("gx")] = localizedCommandLook;
0316     look2typeMap[localizedCommandLook] = Token::GoX;
0317 
0318     localizedCommandLook = ki18nc(
0319         "You are about to translate the 'GoY' COMMAND, there are some rules on how to translate it."
0320         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0321         "goy").toString(localizer);
0322     default2localizedMap[QStringLiteral("goy")] = localizedCommandLook;
0323     look2typeMap[localizedCommandLook] = Token::GoY;
0324 
0325     localizedCommandLook = ki18nc(
0326         "You are about to translate the 'GoY' COMMAND ALIAS, there are some rules on how to translate it."
0327         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0328         "gy").toString(localizer);
0329     default2localizedMap[QStringLiteral("gy")] = localizedCommandLook;
0330     look2typeMap[localizedCommandLook] = Token::GoY;
0331 
0332     localizedCommandLook = ki18nc(
0333         "You are about to translate the 'Forward' COMMAND, there are some rules on how to translate it."
0334         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0335         "forward").toString(localizer);
0336     default2localizedMap[QStringLiteral("forward")] = localizedCommandLook;
0337     look2typeMap[localizedCommandLook] = Token::Forward;
0338 
0339     localizedCommandLook = ki18nc(
0340         "You are about to translate the 'Forward' COMMAND ALIAS, there are some rules on how to translate it."
0341         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0342         "fw").toString(localizer);
0343     default2localizedMap[QStringLiteral("fw")] = localizedCommandLook;
0344     look2typeMap[localizedCommandLook] = Token::Forward;
0345 
0346     localizedCommandLook = ki18nc(
0347         "You are about to translate the 'Backward' COMMAND, there are some rules on how to translate it."
0348         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0349         "backward").toString(localizer);
0350     default2localizedMap[QStringLiteral("backward")] = localizedCommandLook;
0351     look2typeMap[localizedCommandLook] = Token::Backward;
0352 
0353     localizedCommandLook = ki18nc(
0354         "You are about to translate the 'Backward' COMMAND ALIAS, there are some rules on how to translate it."
0355         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0356         "bw").toString(localizer);
0357     default2localizedMap[QStringLiteral("bw")] = localizedCommandLook;
0358     look2typeMap[localizedCommandLook] = Token::Backward;
0359 
0360     localizedCommandLook = ki18nc(
0361         "You are about to translate the 'Direction' COMMAND, there are some rules on how to translate it."
0362         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0363         "direction").toString(localizer);
0364     default2localizedMap[QStringLiteral("direction")] = localizedCommandLook;
0365     look2typeMap[localizedCommandLook] = Token::Direction;
0366 
0367     localizedCommandLook = ki18nc(
0368         "You are about to translate the 'Direction' COMMAND ALIAS, there are some rules on how to translate it."
0369         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0370         "dir").toString(localizer);
0371     default2localizedMap[QStringLiteral("dir")] = localizedCommandLook;
0372     look2typeMap[localizedCommandLook] = Token::Direction;
0373 
0374     localizedCommandLook = ki18nc(
0375         "You are about to translate the 'TurnLeft' COMMAND, there are some rules on how to translate it."
0376         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0377         "turnleft").toString(localizer);
0378     default2localizedMap[QStringLiteral("turnleft")] = localizedCommandLook;
0379     look2typeMap[localizedCommandLook] = Token::TurnLeft;
0380 
0381     localizedCommandLook = ki18nc(
0382         "You are about to translate the 'TurnLeft' COMMAND ALIAS, there are some rules on how to translate it."
0383         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0384         "tl").toString(localizer);
0385     default2localizedMap[QStringLiteral("tl")] = localizedCommandLook;
0386     look2typeMap[localizedCommandLook] = Token::TurnLeft;
0387 
0388     localizedCommandLook = ki18nc(
0389         "You are about to translate the 'TurnRight' COMMAND, there are some rules on how to translate it."
0390         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0391         "turnright").toString(localizer);
0392     default2localizedMap[QStringLiteral("turnright")] = localizedCommandLook;
0393     look2typeMap[localizedCommandLook] = Token::TurnRight;
0394 
0395     localizedCommandLook = ki18nc(
0396         "You are about to translate the 'TurnRight' COMMAND ALIAS, there are some rules on how to translate it."
0397         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0398         "tr").toString(localizer);
0399     default2localizedMap[QStringLiteral("tr")] = localizedCommandLook;
0400     look2typeMap[localizedCommandLook] = Token::TurnRight;
0401 
0402     localizedCommandLook = ki18nc(
0403         "You are about to translate the 'PenWidth' COMMAND, there are some rules on how to translate it."
0404         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0405         "penwidth").toString(localizer);
0406     default2localizedMap[QStringLiteral("penwidth")] = localizedCommandLook;
0407     look2typeMap[localizedCommandLook] = Token::PenWidth;
0408 
0409     localizedCommandLook = ki18nc(
0410         "You are about to translate the 'PenWidth' COMMAND ALIAS, there are some rules on how to translate it."
0411         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0412         "pw").toString(localizer);
0413     default2localizedMap[QStringLiteral("pw")] = localizedCommandLook;
0414     look2typeMap[localizedCommandLook] = Token::PenWidth;
0415 
0416     localizedCommandLook = ki18nc(
0417         "You are about to translate the 'PenUp' COMMAND, there are some rules on how to translate it."
0418         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0419         "penup").toString(localizer);
0420     default2localizedMap[QStringLiteral("penup")] = localizedCommandLook;
0421     look2typeMap[localizedCommandLook] = Token::PenUp;
0422 
0423     localizedCommandLook = ki18nc(
0424         "You are about to translate the 'PenUp' COMMAND ALIAS, there are some rules on how to translate it."
0425         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0426         "pu").toString(localizer);
0427     default2localizedMap[QStringLiteral("pu")] = localizedCommandLook;
0428     look2typeMap[localizedCommandLook] = Token::PenUp;
0429 
0430     localizedCommandLook = ki18nc(
0431         "You are about to translate the 'PenDown' COMMAND, there are some rules on how to translate it."
0432         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0433         "pendown").toString(localizer);
0434     default2localizedMap[QStringLiteral("pendown")] = localizedCommandLook;
0435     look2typeMap[localizedCommandLook] = Token::PenDown;
0436 
0437     localizedCommandLook = ki18nc(
0438         "You are about to translate the 'PenDown' COMMAND ALIAS, there are some rules on how to translate it."
0439         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0440         "pd").toString(localizer);
0441     default2localizedMap[QStringLiteral("pd")] = localizedCommandLook;
0442     look2typeMap[localizedCommandLook] = Token::PenDown;
0443 
0444     localizedCommandLook = ki18nc(
0445         "You are about to translate the 'PenColor' COMMAND, there are some rules on how to translate it."
0446         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0447         "pencolor").toString(localizer);
0448     default2localizedMap[QStringLiteral("pencolor")] = localizedCommandLook;
0449     look2typeMap[localizedCommandLook] = Token::PenColor;
0450 
0451     localizedCommandLook = ki18nc(
0452         "You are about to translate the 'PenColor' COMMAND ALIAS, there are some rules on how to translate it."
0453         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0454         "pc").toString(localizer);
0455     default2localizedMap[QStringLiteral("pc")] = localizedCommandLook;
0456     look2typeMap[localizedCommandLook] = Token::PenColor;
0457 
0458     localizedCommandLook = ki18nc(
0459         "You are about to translate the 'CanvasColor' COMMAND, there are some rules on how to translate it."
0460         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0461         "canvascolor").toString(localizer);
0462     default2localizedMap[QStringLiteral("canvascolor")] = localizedCommandLook;
0463     look2typeMap[localizedCommandLook] = Token::CanvasColor;
0464 
0465     localizedCommandLook = ki18nc(
0466         "You are about to translate the 'CanvasColor' COMMAND ALIAS, there are some rules on how to translate it."
0467         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0468         "cc").toString(localizer);
0469     default2localizedMap[QStringLiteral("cc")] = localizedCommandLook;
0470     look2typeMap[localizedCommandLook] = Token::CanvasColor;
0471 
0472     localizedCommandLook = ki18nc(
0473         "You are about to translate the 'CanvasSize' COMMAND, there are some rules on how to translate it."
0474         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0475         "canvassize").toString(localizer);
0476     default2localizedMap[QStringLiteral("canvassize")] = localizedCommandLook;
0477     look2typeMap[localizedCommandLook] = Token::CanvasSize;
0478 
0479     localizedCommandLook = ki18nc(
0480         "You are about to translate the 'CanvasSize' COMMAND ALIAS, there are some rules on how to translate it."
0481         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0482         "cs").toString(localizer);
0483     default2localizedMap[QStringLiteral("cs")] = localizedCommandLook;
0484     look2typeMap[localizedCommandLook] = Token::CanvasSize;
0485 
0486     localizedCommandLook = ki18nc(
0487         "You are about to translate the 'SpriteShow' COMMAND, there are some rules on how to translate it."
0488         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0489         "spriteshow").toString(localizer);
0490     default2localizedMap[QStringLiteral("spriteshow")] = localizedCommandLook;
0491     look2typeMap[localizedCommandLook] = Token::SpriteShow;
0492 
0493     localizedCommandLook = ki18nc(
0494         "You are about to translate the 'SpriteShow' COMMAND ALIAS, there are some rules on how to translate it."
0495         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0496         "ss").toString(localizer);
0497     default2localizedMap[QStringLiteral("ss")] = localizedCommandLook;
0498     look2typeMap[localizedCommandLook] = Token::SpriteShow;
0499 
0500     localizedCommandLook = ki18nc(
0501         "You are about to translate the 'SpriteHide' COMMAND, there are some rules on how to translate it."
0502         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0503         "spritehide").toString(localizer);
0504     default2localizedMap[QStringLiteral("spritehide")] = localizedCommandLook;
0505     look2typeMap[localizedCommandLook] = Token::SpriteHide;
0506 
0507     localizedCommandLook = ki18nc(
0508         "You are about to translate the 'SpriteHide' COMMAND ALIAS, there are some rules on how to translate it."
0509         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0510         "sh").toString(localizer);
0511     default2localizedMap[QStringLiteral("sh")] = localizedCommandLook;
0512     look2typeMap[localizedCommandLook] = Token::SpriteHide;
0513 
0514     localizedCommandLook = ki18nc(
0515         "You are about to translate the 'Print' COMMAND, there are some rules on how to translate it."
0516         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0517         "print").toString(localizer);
0518     default2localizedMap[QStringLiteral("print")] = localizedCommandLook;
0519     look2typeMap[localizedCommandLook] = Token::Print;
0520 
0521     localizedCommandLook = ki18nc(
0522         "You are about to translate the 'FontSize' COMMAND, there are some rules on how to translate it."
0523         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0524         "fontsize").toString(localizer);
0525     default2localizedMap[QStringLiteral("fontsize")] = localizedCommandLook;
0526     look2typeMap[localizedCommandLook] = Token::FontSize;
0527 
0528     localizedCommandLook = ki18nc(
0529         "You are about to translate the 'Random' COMMAND, there are some rules on how to translate it."
0530         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0531         "random").toString(localizer);
0532     default2localizedMap[QStringLiteral("random")] = localizedCommandLook;
0533     look2typeMap[localizedCommandLook] = Token::Random;
0534 
0535     localizedCommandLook = ki18nc(
0536         "You are about to translate the 'Random' COMMAND ALIAS, there are some rules on how to translate it."
0537         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0538         "rnd").toString(localizer);
0539     default2localizedMap[QStringLiteral("rnd")] = localizedCommandLook;
0540     look2typeMap[localizedCommandLook] = Token::Random;
0541 
0542     localizedCommandLook = ki18nc(
0543         "You are about to translate the 'GetX' COMMAND, there are some rules on how to translate it."
0544         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0545         "getx").toString(localizer);
0546     default2localizedMap[QStringLiteral("getx")] = localizedCommandLook;
0547     look2typeMap[localizedCommandLook] = Token::GetX;
0548 
0549     localizedCommandLook = ki18nc(
0550         "You are about to translate the 'GetY' COMMAND, there are some rules on how to translate it."
0551         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0552         "gety").toString(localizer);
0553     default2localizedMap[QStringLiteral("gety")] = localizedCommandLook;
0554     look2typeMap[localizedCommandLook] = Token::GetY;
0555 
0556     localizedCommandLook = ki18nc(
0557         "You are about to translate the 'Message' COMMAND, there are some rules on how to translate it."
0558         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0559         "message").toString(localizer);
0560     default2localizedMap[QStringLiteral("message")] = localizedCommandLook;
0561     look2typeMap[localizedCommandLook] = Token::Message;
0562 
0563     localizedCommandLook = ki18nc(
0564         "You are about to translate the 'Ask' COMMAND, there are some rules on how to translate it."
0565         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0566         "ask").toString(localizer);
0567     default2localizedMap[QStringLiteral("ask")] = localizedCommandLook;
0568     look2typeMap[localizedCommandLook] = Token::Ask;
0569 
0570     localizedCommandLook = ki18nc(
0571         "You are about to translate the 'Pi' COMMAND, there are some rules on how to translate it."
0572         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0573         "pi").toString(localizer);
0574     default2localizedMap[QStringLiteral("pi")] = localizedCommandLook;
0575     look2typeMap[localizedCommandLook] = Token::Pi;
0576 
0577     localizedCommandLook = ki18nc(
0578         "You are about to translate the 'Tan' COMMAND, there are some rules on how to translate it."
0579         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0580         "tan").toString(localizer);
0581     default2localizedMap[QStringLiteral("tan")] = localizedCommandLook;
0582     look2typeMap[localizedCommandLook] = Token::Tan;
0583 
0584     localizedCommandLook = ki18nc(
0585         "You are about to translate the 'Sin' COMMAND, there are some rules on how to translate it."
0586         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0587         "sin").toString(localizer);
0588     default2localizedMap[QStringLiteral("sin")] = localizedCommandLook;
0589     look2typeMap[localizedCommandLook] = Token::Sin;
0590 
0591     localizedCommandLook = ki18nc(
0592         "You are about to translate the 'Cos' COMMAND, there are some rules on how to translate it."
0593         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0594         "cos").toString(localizer);
0595     default2localizedMap[QStringLiteral("cos")] = localizedCommandLook;
0596     look2typeMap[localizedCommandLook] = Token::Cos;
0597 
0598     localizedCommandLook = ki18nc(
0599         "You are about to translate the 'ArcTan' COMMAND, there are some rules on how to translate it."
0600         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0601         "arctan").toString(localizer);
0602     default2localizedMap[QStringLiteral("arctan")] = localizedCommandLook;
0603     look2typeMap[localizedCommandLook] = Token::ArcTan;
0604 
0605     localizedCommandLook = ki18nc(
0606         "You are about to translate the 'ArcSin' COMMAND, there are some rules on how to translate it."
0607         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0608         "arcsin").toString(localizer);
0609     default2localizedMap[QStringLiteral("arcsin")] = localizedCommandLook;
0610     look2typeMap[localizedCommandLook] = Token::ArcSin;
0611 
0612     localizedCommandLook = ki18nc(
0613         "You are about to translate the 'ArcCos' COMMAND, there are some rules on how to translate it."
0614         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0615         "arccos").toString(localizer);
0616     default2localizedMap[QStringLiteral("arccos")] = localizedCommandLook;
0617     look2typeMap[localizedCommandLook] = Token::ArcCos;
0618 
0619     localizedCommandLook = ki18nc(
0620         "You are about to translate the 'Sqrt' COMMAND, there are some rules on how to translate it."
0621         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0622         "sqrt").toString(localizer);
0623     default2localizedMap[QStringLiteral("sqrt")] = localizedCommandLook;
0624     look2typeMap[localizedCommandLook] = Token::Sqrt;
0625 
0626     localizedCommandLook = ki18nc(
0627         "You are about to translate the 'Round' COMMAND, there are some rules on how to translate it."
0628         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0629         "round").toString(localizer);
0630     default2localizedMap[QStringLiteral("round")] = localizedCommandLook;
0631     look2typeMap[localizedCommandLook] = Token::Round;
0632 
0633     localizedCommandLook = ki18nc(
0634         "You are about to translate the 'GetDirection' COMMAND, there are some rules on how to translate it."
0635         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0636         "getdirection").toString(localizer);
0637     default2localizedMap[QStringLiteral("getdirection")] = localizedCommandLook;
0638     look2typeMap[localizedCommandLook] = Token::GetDirection;
0639 
0640     localizedCommandLook = ki18nc(
0641         "You are about to translate the 'Mod' COMMAND, there are some rules on how to translate it."
0642         "Please see https://edu.kde.org/kturtle/translator.php to learn how to properly translate it.",
0643         "mod").toString(localizer);
0644     default2localizedMap[QStringLiteral("mod")] = localizedCommandLook;
0645     look2typeMap[localizedCommandLook] = Token::Mod;
0646 
0647 
0648 //END GENERATED translator_cpp CODE
0649 
0650 }
0651 
0652 
0653 
0654 void Translator::setExamples()
0655 {
0656     examples.clear();
0657     QString exampleName;
0658 
0659     exampleName = ki18nc(
0660         "This is an EXAMPLE NAME in KTurtle."
0661         "Please see https://edu.kde.org/kturtle/translator.php to learn know how to properly translate it.",
0662         "triangle").toString(localizer);
0663     examples[exampleName] = localizeScript(QStringLiteral(
0664                 "@(reset)\n"
0665                 "@(repeat) 3 {\n"
0666                 "  @(forward) 100\n"
0667                 "  @(turnleft) 120\n"
0668                 "}\n"
0669         ));
0670 
0671     exampleName = ki18nc(
0672         "This is an EXAMPLE NAME in KTurtle."
0673         "Please see https://edu.kde.org/kturtle/translator.php to learn know how to properly translate it.",
0674         "curly").toString(localizer);
0675     examples[exampleName] = localizeScript(QStringLiteral(
0676                 "@(reset)\n"
0677                 "@(penup)\n"
0678                 "@(forward) 50\n"
0679                 "@(pendown)\n"
0680                 "\n"
0681                 "@(repeat) 4 {\n"
0682                 "  @(for) $x = 1 @(to) 100 {\n"
0683                 "    @(forward) 10\n"
0684                 "    @(turnright) 100 - $x\n"
0685                 "  }\n"
0686                 "}\n"
0687         ));
0688 
0689     exampleName = ki18nc(
0690         "This is an EXAMPLE NAME in KTurtle."
0691         "Please see https://edu.kde.org/kturtle/translator.php to learn know how to properly translate it.",
0692         "arrow").toString(localizer);
0693     examples[exampleName] = localizeScript(QStringLiteral(
0694                 "@(reset)\n"
0695                 "\n"
0696                 "@(canvassize) 200@(,) 200\n"
0697                 "@(canvascolor) 0@(,) 0@(,) 0\n"
0698                 "@(pencolor) 255@(,) 0@(,) 0\n"
0699                 "@(penwidth) 5\n"
0700                 "\n"
0701                 "@(go) 20@(,)20\n"
0702                 "@(direction) 135\n"
0703                 "\n"
0704                 "@(forward) 200\n"
0705                 "@(turnleft) 135\n"
0706                 "@(forward) 100\n"
0707                 "@(turnleft) 135\n"
0708                 "@(forward) 141\n"
0709                 "@(turnleft) 135\n"
0710                 "@(forward) 100\n"
0711                 "@(turnleft) 45\n"
0712                 "\n"
0713                 "@(go) 40@(,) 100"
0714         ));
0715 
0716     exampleName = ki18nc(
0717         "This is an EXAMPLE NAME in KTurtle."
0718         "Please see https://edu.kde.org/kturtle/translator.php to learn know how to properly translate it.",
0719           "flower").toString(localizer);
0720     examples[exampleName] = localizeScript(QStringLiteral(
0721                 "@(reset)\n"
0722                 "@(canvascolor) 255@(,) 55@(,) 140\n"
0723                 "@(pencolor) 160@(,) 0@(,) 255\n"
0724                 "@(penwidth) 3\n"
0725                 "\n"
0726                 "@(repeat) 8 {\n"
0727                 "  @(repeat) 4 {\n"
0728                 "    @(forward) 20\n"
0729                 "    @(turnright) 30\n"
0730                 "  }\n"
0731                 "  @(repeat) 7 {\n"
0732                 "    @(forward) 10\n"
0733                 "    @(turnright) 15\n"
0734                 "  }\n"
0735                 "  @(repeat) 9 {\n"
0736                 "    @(forward) 3\n"
0737                 "    @(turnright) 10\n"
0738                 "  }\n"
0739                 "}\n"
0740                 "\n"
0741                 "@(go) 145@(,) 145\n"
0742                 "@(direction) 0"
0743         ));
0744 
0745 }
0746 
0747 QString Translator::localizeScript(const QString& untranslatedScript)
0748 {
0749     QString result = untranslatedScript;
0750     Translator* translator = Translator::instance();
0751     QRegExp rx(QStringLiteral("@\\(.*\\)"));
0752     rx.setMinimal(true);  // make it not greedy
0753 
0754     int pos = 0;
0755     while ((pos = rx.indexIn(result, pos)) != -1) {
0756         QString original = result.mid(pos, rx.matchedLength());
0757         original = original.mid(2, original.length() - 3);
0758         result.replace(pos, rx.matchedLength(), translator->default2localized(original));
0759     }
0760 
0761     return result;
0762 }