-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for contextual translation and small gettext corrections #17
Support for contextual translation and small gettext corrections #17
Conversation
Foreign languages may need to move the app name according to their needs
If you don't mind, I wouldn't add these new functions to a separate |
That's what I first did, but it then throws a lot of warnings because the function is not used in every file depending on "translation.hpp" |
You'd have to split it into a .hpp and .cpp file for C++ to not throw multiple definition warnings. Try implementing it like this:
#pragma once
#include <libintl.h>
#include <locale.h>
#define _(String) gettext(String)
const char* pgettext_aux(const char* msg_ctxt_id, const char* msgid);
#define GETTEXT_CONTEXT_GLUE "\004"
#define pgettext(Ctxt, String) pgettext_aux(Ctxt GETTEXT_CONTEXT_GLUE String, String)
#include "translation.hpp"
const char* pgettext_aux(const char* msg_ctxt_id, const char* msgid)
{
const char* translation{ dcgettext(GETTEXT_PACKAGE, msg_ctxt_id, LC_MESSAGES) };
if (translation == msg_ctxt_id)
{
return msgid;
}
return translation;
} (Don't forget to add the translation.cpp to the src/meson.build) |
I'm pretty sure I added something like that and I always ended up having the linker not recognizing my function... And now for some obscure reason it works... I committed these changes |
It might have been because you put the |
Just one minor thing...could you move the |
Done |
Beautiful! Thank you! |
What?
Added support for contextual translation, that means translating a same English word/sentence in several different words/sentences depending on the context.
Why?
As explained in this issue comment, one same word has to be translated differently depending on where it is in the UI.
How?
This version adds the
pgettext
function in src/helpers/contextualtranslation.hpp, which allows to add a context as first argument. This context is then added in the po file with themsgctxt
property automatically. Several entries can now have the same id but are differentiated by their context.Small tweaks
This version also takes care of :