Вопрос

I'd like to use variables in some way in gettext .po files, for example:

msgid "ui_settings_connect_text"
msgstr "Connect to another running instance of " APP_NAME

Has anyone tried to do something like this before?

Это было полезно?

Решение

In your .po file:

msgid "Connect to another running instance of %s"
msgstr "Connect to another running instance of %s"

In your app:

printf(_("Connect to another running instance of %s"), app_name);

Другие советы

I made a preprocessor to do this as well, as I don't believe the application code should be coupled to whether some text will contain the application name (to use Tom's example), or any other translated snippets.

I've put source up on github and provided a Windows .exe, but if you're not using Windows it will need Mono.

https://github.com/Treer/POpp

To solve the problem proposed by Tom, the .po file would look like this:

msgid "APP_NAME"
msgstr "Tom's app"

msgid "ui_settings_connect_text"
msgstr "Connect to another running instance of {id:APP_NAME}"

Which should be useable in any GUI PO editor.

The preprocessor is just run like this:

popp source.po destination.po
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top