-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Romex91 edited this page Feb 24, 2016
·
8 revisions
This header-only library provides simple solution for string literals internationalization in c++. I started the library when developing a client-server application with requrement to run multiple clients with different languages. The server sources contained bunch of string literals. I had to somehow send the literals to clients using boost asio and translate them to appropriate languages on the client side.
So I needed a solution with the next features:
- keeping translations in XML files (string resources)
- using the literals as ids. Something like Qt tr()
- the literals contain placeholders replacing with variables. i.e: "Access for user {0} denied. Reason: {1}"
- converting literals to numeric ids when serializing and loading the appropriate translation on the client side
Here is the comprehensive usage example: https://github.com/Romex91/ResourceString/blob/master/ResourceString/Sample.cpp
- use _rstrw() macro for all the literals to be translated
- preprocessor would print all the literals to the compiler output. You should pass the build log to _rstrw_t::resource().addStringsFromCompilerOutput() and save the resource to an xml file using boost serailization.
- after the string resource is created you should translate it to languages you want creating separate xmls. Write your translations to nodes "second". Nodes "first" shouldn't be changed
- when the resources ready you can work with _rstrw_t objects. To get translation run _rstrw_t::str(). Use boost serailisation to save string id and parameters pack.