Здравствуйте, _hum_, Вы писали:
__>константы надо два раза упоминать — при определении и при маппинге
| | langs\ru-RU.h |
| | LOCALIZATION_ITEM(hello, "Привет")
LOCALIZATION_ITEM(bye, "Пока")
|
| | |
| | langs\en-US.h |
| | LOCALIZATION_ITEM(hello, "Hello")
LOCALIZATION_ITEM(bye, "Bye")
|
| | |
| | langs\current.h |
| | #ifndef LANG_ID
# define LANG_ID__EN_US 0x0409
# define LANG_ID__RU_RU 0x0419
# define LANG_ID LANG_ID__RU_RU
#endif // LANG_ID
#if LANG_ID == LANG_ID__EN_US
# include "langs\en-US.h"
#elif LANG_ID == LANG_ID__RU_RU
# include "langs\ru-RU.h"
#endif
|
| | |
| | localization.h |
| | #ifndef LOCALIZATION_H
#define LOCALIZATION_H
#include <string>
namespace localization
{
enum class msg_id
{
unknown = 0,
#define LOCALIZATION_ITEM(id, message) id,
#include "langs\current.h"
#undef LOCALIZATION_ITEM
};
std::string message(msg_id id);
} // namespace localization
#endif // LOCALIZATION_H
|
| | |
| | localization.cpp |
| | #include <exception>
#include "localization.h"
namespace localization
{
std::string message(msg_id id)
{
switch (id)
{
case msg_id::unknown:
return std::string();
#define LOCALIZATION_ITEM(id, message) case msg_id::id: return std::string(message);
#include "langs\current.h"
#undef LOCALIZATION_ITEM
default:
throw std::runtime_error("bad msg_id");
}
}
} // namespace localization
|
| | |
| | main.cpp |
| | #include <iostream>
#include "localization.h"
int main(int, char**)
{
std::cout << localization::message(localization::msg_id::hello) << std::endl;
std::cout << localization::message(localization::msg_id::bye) << std::endl;
return 0;
}
|
| | |