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;
    }
  • 相关阅读:
    MySQL--自增列持久化问题
    MySQL--”自然键”和”代理键”优缺点
    MySQL--REPLACE INTO更新自增列值引发的异常
    MySQL Inception--原理和注意事项
    MySQL Inception--安装
    MySQL--关联更新
    MySQL--Delete语句别名+LIMIT
    MySQL Disk--SSD 特性
    BootStrap简介
    BootStrap简单使用
  • 原文地址:https://www.cnblogs.com/kingBook/p/5613491.html
Copyright © 2011-2022 走看看