質問

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