Internationalization

From K-3D

Jump to: navigation, search

Overview

Enjoy K-3D in the "Swedish Chef" locale!

Beginning with version 0.5, K-3D provides Native Language Support using the GNU gettext library. This article covers K-3D internationalization, which is the process of writing code that can be used with different locales (language translations). For information on how to translate the K-3D user interface into different locales, see Localization. To specify your preferred language when running K-3D see Native Language Support.

References

String Internationalization

At the top of your file to be localized, add:

#include <k3d-i18n-config.h>

Then, use the "_()" macro to mark all string constants that should be localized:

print_message(_("Howdy, World!"));

Don't mark error strings, XML tags, scripting language symbols, or command-node names for localization.

Never mark the empty string ("") for localization.

Don't build strings using sentence fragments or concatenation operators. Use the Boost Format library, which provides printf-style formatting strings with positional parameters, type-safety, and support for user-defined types. As an example, the following hypothetical code cannot be correctly translated because sentence structure and punctuation may very from language-to-language:

_("Hello, ") + user_name + _(", your current age is ") + age + _(" years")

Instead, you would use a formatting string and Boost Format:

k3d::string_cast(boost::format(_("Hello, %1%, your current age is %2% years")) % user_name % age);

... which allows the translator to reorder the structure of the sentence as-needed. Note the use of the positional parameters, "%1%" and "%2%", which ensure that the arguments are formatted in the correct order, even if their order within the format string changes in translation.

Note: Internationalization is enabled at configure-time using the K3D_BUILD_NLS cmake option

File Internationalization

Beginning in K-3D 0.6.7.0, we have converted all filesystem path storage from boost::filesystem::path to k3d::filesystem::path. The new k3d::filesystem::path class is nearly identical to its boost counterpart, but internally stores a UTF-8 string instead of std::string. It also provides a wider variety of explicit conversions from internal storage to external formats, and eliminates some problematic implicit conversions that tended to lead to coding errors.

Personal tools