tb_language.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #ifndef TB_LANGUAGE_H
  6. #define TB_LANGUAGE_H
  7. #include "tb_core.h"
  8. #include "tb_hashtable.h"
  9. #include "tb_id.h"
  10. namespace tb {
  11. /** TBLanguage is a basic language string manager.
  12. Strings read into it can be looked up from a TBID, so either by a number
  13. or the hash number from a string (done by TBID).
  14. Ex: GetString(10) (Get the string with id 10)
  15. Ex: GetString("new") (Get the string with id new)
  16. In UI resources, you can refer to strings from language lookup by preceding a string with @.
  17. Ex: TBButton: text: @close (Create a button with text from lookup of "close")
  18. */
  19. class TBLanguage
  20. {
  21. public:
  22. ~TBLanguage();
  23. /** Load a file into this language manager.
  24. Note: This *adds* strings read from the file, without clearing any existing
  25. strings first. */
  26. bool Load(const char *filename);
  27. /** Clear the list of strings. */
  28. void Clear();
  29. /** Return the string with the given id.
  30. If there is no string with that id, "<TRANSLATE!>" will be returned
  31. in release builds, and "<TRANSLATE:%s>" (populated with the id) will
  32. be returned in debug builds. */
  33. const char *GetString(const TBID &id);
  34. private:
  35. TBHashTableOf<TBStr> strings;
  36. };
  37. };
  38. #endif // TB_LANGUAGE_H