Coder Social home page Coder Social logo

as01788 / languageframework Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 4.0 4.27 MB

基于Cocos Creator 2.4.2开发的多语言框架(项目读取资源用到Asset Bundle来读取资源),支持实时动态修改Sprite、Label、RichText、Font。

TypeScript 100.00%

languageframework's Introduction

LanguageFramework

基于Cocos Creator 2.4.2开发的多语言框架(项目读取资源用到Asset Bundle来读取资源),支持实时动态修改Sprite、Label、RichText、Font。


效果图

image

image


JsonUI

  • 作用:通过节点路径给相应的组件动态修改相应的内容。

  • Json文件放在resources文件夹下

  • 使用需求:

     1. Json配置
     2. language.json配置
     3. 给相应的节点挂上JsonUI脚本并赋予json文件路径(默认根目录为resources)
     4. JsonUIManager.Init初始化一下language.json文件(默认路径为resources/language.json)
    
  • 使用方法:首先配置好UI和Json文件,然后在任意start生命周期中JsonUIManager.Init一下即可(不可再onload中,因为JsonSprite、JsonLabel、JsonUI组件要注册事件,不然这几个组件首次切换语言将无效),可通过JsonUIManager.SwitchLanguage来动态切换语言。


JsonUI配置规则

例子:"Info": {

​ "UICompontents": [

​ {

​ "path":"this",

​ "uiType": "Image",

​ "resName": "test"

​ },

​ {

​ "path”:"bg",

​ "uiType": "Image",

​ "bundleName”:"resources"

​ "resName": "test"

​ }

​ ]

​ }

  1. 对象名称:Info(可修改,不过需要在JsonUI组件中也同时修改)
  2. UICompontents为必选项,是一个数组
UICompontents说明
  • 键值有:path、uiType、bundleName(可选)、resName。

  • path:节点路径,已自身为起点开始往下找,this为自身节点。

  • uiType:组件类型,现有Label(包含RichText)、Image、Font。

  • bundleName:bundle名称(可选项,如果填了将优先使用这个,替代掉了json配置的info.language)。

  • resName:资源名称,资源类型为资源名称,字符串类型为language.json的对象。


language.json说明

  • 作用:配置各个语言所用的文本,可通过id获得相应的文本。

  • 每个对象对应一个id(这里的id是给UICompontents的resName项用的),之后的语言是可选的。

  • 只能存在一个language.json并且放在resources根目录下,也可以自己到JsonUIManager修改路径。

  • 可用JsonLabel组件或JsonUIManager.GetLanguage(id)来获取文本。

  • 示例:{

    ​ "languages":[

    ​ {

    ​ "id":"test",

    ​ "cn": "哈哈哈哈哈哈哈哈",

    ​ "en": "hahahahahahaha"

    ​ },

    ​ {

    ​ "id":"test2",

languageframework's People

Contributors

as01788 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.