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;
    }
  • 相关阅读:
    存储过程参数不能使用函数
    .gitignore git已跟踪文件不生效
    Css选择器-层次选择器(关系选择器)
    Mysql自定义变量的作用
    jQuery 鼠标滑过Div变色
    DataTable导出excel 设置单元格格式
    layui table 详细讲解
    npm 常用命令详解
    SQL Server 2008下轻松调试T-SQL语句和存储过程
    帆软报表常用功能
  • 原文地址:https://www.cnblogs.com/kingBook/p/5613491.html
Copyright © 2011-2022 走看看