LocalizationMgr.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // LocalizationMgr.hpp
  3. // redream_runtime
  4. //
  5. // Created by ZhengSong on 2022/7/11.
  6. //
  7. #ifndef LocalizationMgr_h
  8. #define LocalizationMgr_h
  9. #include "cocos2d.h"
  10. NS_CC_BEGIN
  11. class LocalizationMgr {
  12. public:
  13. static LocalizationMgr* getInstance();
  14. bool init();
  15. /* 通过key转化为当前国家的语言
  16. * @param Label的string value
  17. * @param 本地化文件
  18. */
  19. /// 通过key转化为当前国家的语言
  20. /// @param key key-value
  21. /// @param fileName 本地化配置文件
  22. std::string getString(const std::string &key, const std::string &fileName);
  23. /* 设置当前国家的语言
  24. * @param code 国家编码
  25. */
  26. void setCurrentLanguageCode(const std::string& code);
  27. std::string getCurrentLanguageCode() const;
  28. private:
  29. /// 缓存读过的配置文件
  30. /// @param fileName fileName
  31. const cocos2d::ValueMap _getFileFromCache(const std::string& fileName);
  32. private:
  33. std::unordered_map<std::string, ValueMap> _plistMap;
  34. std::string _currentLanguageCode; //默认值为设备当前语言
  35. };
  36. NS_CC_END
  37. #endif /* LocalizationMgr_hpp */