zoukankan      html  css  js  c++  java
  • cocos2d-x 获得系统语言繁体

    IosLocalUtil.h

    #ifndef __IOS_LOCALUTIL_H__
    #define __IOS_LOCALUTIL_H__
    class IosLocalUtil{
    public:
        static IosLocalUtil*getInstance();
        bool getIsTaiwanChinese();
        std::string getCurrentLanguage() const;
    private:
        static IosLocalUtil*_instance;
    };
    #endif /* __IOS_LOCALUTIL_H__*/

    IosLocalUtil.mm

    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <GameKit/GameKit.h>
    
    #import "IosLocalUtil.h"
    #import "cocos2d.h"
    
    ////////////////////////////////////////////////////////////////////////////////////////////////
    //                                              objective-c
    ////////////////////////////////////////////////////////////////////////////////////////////////
    @interface LocalUtilHelper: NSObject <GKLeaderboardViewControllerDelegate, GKAchievementViewControllerDelegate, GKMatchmakerViewControllerDelegate, GKMatchDelegate>{
        
    }
    //@property (nonatomic, assign) IosLocalUtil*cCaller;
    + (LocalUtilHelper *)getInstance;
    - (NSString*)getCurrentLanguage;
    @end
    //---------------------------------------------------------------------------------------
    
    @implementation LocalUtilHelper
    
    //静态初始化 对外接口
    static LocalUtilHelper *_instance = nil;
    + (LocalUtilHelper *) getInstance {
        if (!_instance) {
            _instance = [[LocalUtilHelper alloc] init];
        }
        return _instance;
    }
    
    - (id)init {
        if ((self = [super init])){
            
        }
        return self;
    }
    
     //得到本机现在用的语言
    - (NSString*)getCurrentLanguage{
        NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
        NSArray* languages = [defaults objectForKey:@"AppleLanguages"];
        NSString* currentLanguage = [languages objectAtIndex:0];
        return currentLanguage;
    }
    @end
    
    
    
    ////////////////////////////////////////////////////////////////////////////////////////////////
    //                                              c++
    ////////////////////////////////////////////////////////////////////////////////////////////////
    IosLocalUtil* IosLocalUtil::_instance=nullptr;
    IosLocalUtil* IosLocalUtil::getInstance(){
        if(_instance==nullptr){
            _instance=new IosLocalUtil();
           // [LocalUtilHelper getInstance].cCaller=_instance;
        }
        return _instance;
    }
    
    std::string IosLocalUtil::getCurrentLanguage() const{
        NSString* nsStr=[[LocalUtilHelper getInstance] getCurrentLanguage];
       // const char* lpfaceName = [nsStr UTF8String];
        std::string language=[nsStr UTF8String];
        return language;
    }
    
    /**
     * HongKong:zh-HK, Taiwan:zh-TW, fanTi: zh-Hant-CN
     */
    bool IosLocalUtil::getIsTaiwanChinese(){
    #if(CC_TARGET_PLATFORM==CC_PLATFORM_IOS)
        NSString* nsStr=[[LocalUtilHelper getInstance] getCurrentLanguage];
        std::string language=[nsStr UTF8String];
        return language=="zh-HK"||language=="zh-TW"||language=="zh-Hant-CN"||language=="zh-Hant";
    #endif
    return false;
    }
  • 相关阅读:
    使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration
    Mysql Lost connection to MySQL server at ‘reading initial communication packet', system error: 0
    mysql-基本命令
    C# 监听值的变化
    DataGrid样式
    C# 获取当前日期时间
    C# 中生成随机数
    递归和迭代
    PHP 时间转几分几秒
    PHP 根据整数ID,生成唯一字符串
  • 原文地址:https://www.cnblogs.com/kingBook/p/5613491.html
Copyright © 2011-2022 走看看