how to define repeated string with qtranslator?
-
It's because the context is wrong - it's not QObject but your class name ('Dll' in your example).
Still don't understand the reason behind all this. If you want some kind of translation library you should use a proper class with a get() function which takes an enum which represents your stringclass Translator : public QObject { Q_OBJECT public: enum class Id { Hello1, Hello2, } QString translateMe(Id id) const; } ... QString Translator::translateMe(Id id) const { switch (id) { case Id::Hello1: return tr("Hello1"); case Id::Hello2: return tr("Hello2"); } }
-
It's because the context is wrong - it's not QObject but your class name ('Dll' in your example).
Still don't understand the reason behind all this. If you want some kind of translation library you should use a proper class with a get() function which takes an enum which represents your stringclass Translator : public QObject { Q_OBJECT public: enum class Id { Hello1, Hello2, } QString translateMe(Id id) const; } ... QString Translator::translateMe(Id id) const { switch (id) { case Id::Hello1: return tr("Hello1"); case Id::Hello2: return tr("Hello2"); } }
wrote on 1 Dec 2021, 07:58 last edited by QtTester 12 Jan 2021, 07:58@Christian-Ehrlicher said in how to define repeated string with qtranslator?:
class Translator : public QObject
{
Q_OBJECT
public:
enum class Id
{
Hello1,
Hello2,
}
QString translateMe(Id id) const;
}QString Translator::translateMe(Id id) const
{
switch (id) {
case Id::Hello1: return tr("Hello1");
case Id::Hello2: return tr("Hello2");
}
}That is what I first said: write a common、 stand alone project and call it's API.
-
@Christian-Ehrlicher said in how to define repeated string with qtranslator?:
class Translator : public QObject
{
Q_OBJECT
public:
enum class Id
{
Hello1,
Hello2,
}
QString translateMe(Id id) const;
}QString Translator::translateMe(Id id) const
{
switch (id) {
case Id::Hello1: return tr("Hello1");
case Id::Hello2: return tr("Hello2");
}
}That is what I first said: write a common、 stand alone project and call it's API.
@QtTester said in how to define repeated string with qtranslator?:
That is what I first said: write a common、 stand alone project and call it's API.
So what's the actual problem then?
-
@QtTester said in how to define repeated string with qtranslator?:
That is what I first said: write a common、 stand alone project and call it's API.
So what's the actual problem then?
wrote on 1 Dec 2021, 08:09 last edited by@Christian-Ehrlicher said in how to define repeated string with qtranslator?:
@QtTester said in how to define repeated string with qtranslator?:
That is what I first said: write a common、 stand alone project and call it's API.
So what's the actual problem then?
guys said it is overcomplicate or no need to do this , so i try to find another native way .after a long circle way , you give me the same solution. ha-ha-ha
-
I would not use this solution but translate it more than once - it's easier esp. since linguist auto-translates your strings when it already find the exact same match.
-
I would not use this solution but translate it more than once - it's easier esp. since linguist auto-translates your strings when it already find the exact same match.
wrote on 1 Dec 2021, 09:05 last edited by@Christian-Ehrlicher said in how to define repeated string with qtranslator?:
e
How do you solve this situation:
Project1 dll1 dll2 app Project2 dll3 dll4 app
Project1 and Project2 or other projects need to use the same string. many many string(like ok, yes, no ...)
if you translate each BIg Project, you donot need to do the repetitive work?
and you cannot put dll1.ts to Project2, you mean linguist know it's already translated?
21/26