目录

  • I2 localization简单介绍
  • 购买地址
  • 简单使用介绍
    • 语言管理器
    • 场景中的UI设置
      • 内容
      • 字体
      • 样式
    • 添加脚本
    • 相关API
      • 设置当前语言
      • 获取当前语言地区
      • 访问本地化
      • LocalizedString类
      • 修改localize属性
      • 在线翻译
      • 导入CSV文件

I2 localization简单介绍

I2 localization是一个Unity3D可用的本地化插件。
没有找到比较系统的介绍,一句话说,就是用来改语言的。

购买地址

https://assetstore.unity.com/packages/tools/localization/i2-localization-14884?aid=1101l4nxF
要$45,公司让学习一下,就简单学一下,我自己就不买了

简单使用介绍

语言管理器

添加组件之后会有这样的显示,language这里是设置对应的语言的,下面有一个小的搜索框,可以搜索其他语言,设置之后terms下面可以看到相应的变化。

Terms相当于词条,下面是预置好的一些词条,比如这个游戏登录的

可以直接在这里点加号进行添加,可以在一开始设置key的时候用/,比如上面的title就是hall/login/title,这样在后面找起来比较方便,就像拥有了一个目录的模式。

场景中的UI设置

内容

给场景中的UI添加一个Localize组件,这里的Target是对应UI的类型,Main选择对应的Term,就会看到之前设置好的词条。Open Source选择刚才设置了语言管理器的预置体拖进去。这里可以设置不同语言的内容。

字体

组件的secondary的term可以选择Font类型,定义了不同语言的字体,这个term也是可以添加在资源库里面的:

样式

I2 Localization doesn’t provide a way to adjust the size directly as that could make more confusing the inspector (that is already crowdy) by introducing another setting per-language.

I2 Localization不能直接修改不同语言对应的字体大小,但是可以通过下面的方式(富文本)来修改。

添加脚本

选择Tools下面的Script,点Build Script with。。。就可以在脚本里面看到生成了相应的代码。


【原谅我这个花花的马赛克,毕竟公司代码,不能随便泄露,还是要谨慎点好】
后面的估计还没写好,找不到了,算了,以后再说。。

相关API

http://www.inter-illusion.com/assets/I2LocalizationManual/CommonlyusedScriptAPIs.html

设置当前语言

// Change the Current Language
I2.Loc.LocalizationManager.CurrentLanguage = "English";
I2.Loc.LocalizationManager.CurrentLanguage = "English (Canada)";  //Language and Variant
I2.Loc.LocalizationManager.CurrentLanguage = "English Canada";    //another way of setting it// or
I2.Loc.LocalizationManager.CurrentLanguageCode = "en";
I2.Loc.LocalizationManager.CurrentLanguageCode = "en-US";
I2.Loc.LocalizationManager.CurrentLanguageCode = "en-CA";

注意点

When setting a language without a variant (e.g. “English”), the plugin changes to the first “English” language in the language Source list (e.g. “English (Canada)”)
If a variant is provided, but it can’t be found in the languageSource (e.g. setting “English (Canada)” but only “English (United State)” and “English (Australia)” are defined in the LanguageSource), then the plugin strips the variant part, and find the first “English” language in that list.

设置语言没有变体或者没有找到这个变体,会选择当前语言的第一个,当前语言也没有找到就不改变。

上图中语言列表是 Spanish、English(United States)、English(Canada)这三种语言,设置Chinese的时候就会由于找不到语言不改变。

获取当前语言地区

// When current Language is "English (United States)"
string region = I2.Loc.LocalizationManager.CurrentRegion     // returns "United States"
I2.Loc.LocalizationManager.CurrentRegion = "Canada"     // the new language will be "English (Canada)"// When current Language Code is "en-US"
string region = I2.Loc.LocalizationManager.CurrentRegionCode     // returns "US"
I2.Loc.LocalizationManager.CurrentRegion = "CA"            // the new language code will be "en-CA"

访问本地化

获取当前语言情况下,MyKey的翻译

// Get the translation of MyKey into the Current Language
string text1 = I2.Loc.LocalizationManager.GetTranslation("MyKEY");                      // Term in the Default (empty) category
string text2 = I2.Loc.LocalizationManager.GetTranslation("Tutorial/MyKEY");          // Term in the Tutorial category
string text2 = I2.Loc.LocalizationManager.GetTranslation("Tutorial/Tips/MyKEY");   // Nested Categories

为了避免拼写错误,可以直接使用前面的脚本工具

// The previous examples could be rewritten in this way for safer access:
string text1 = I2.Loc.ScriptLocalization.MyKEY;                      // MyKey is a generated property
string text2 = I2.Loc.ScriptLocalization.Tutorial.MyKEY;          // MyKey is a property inside the Tutorial structure
string text2 = I2.Loc.ScriptLocalization.Tutorial.Tips.MyKEY;

LocalizedString类

LocalizedString类是常规字符串的替换,该字符串会自动将其内容转换为当前语言。在将值分配给LocalizedString时,它使用Term的名称,当获得值时,它会返回Term的翻译。

LocalizedString locString = "Term2";LocalizationManager.CurrentLanguage = "English";
string translation = locString;   // returns the translation of Term2 to English (e.g. 'This is an example')LocalizationManager.CurrentLanguage = "Spanish";
string translation = locString;   // returns the translation of Term2 to Spanish (e.g. 'Este es un ejemplo')

修改localize属性

可以通过代码动态设置或者修改term。

// Access the Localize component in the label
var localize = label.GetComponent<Localize>();
// Change the term
localize.SetTerm( "REWARD_1");                      // Only the Primary term (secondary is left unchanged)
// or
localize.SetTerm("REWARD_2", "FONT_2")         // Change the Primary and Secondary Terms

在线翻译

查询谷歌翻译,把“en(英语)”翻译成“es(西班牙语)”。

// Query google for the Translation and waits until google returns
string text = I2.Loc.GoogleTranslation.ForceTranslate("Hello World", "en", "es");

等待返回的结果中执行OnTranslationReady()。

// Async: (Preferred Method) Translate English to Spanish
//        and calls OnTranslationReady when finished
//        The game continues running while waiting for Google
public void TestFunc()
{GoogleTranslation.Translate("Hello World", "en", "es", OnTranslationReady);
}
public void OnTranslationReady( string result )
{}

导入CSV文件

从云端服务器下载CSV文件。

// Calling DownloadCSV will download the file and call UseLocalizationCSV with the file content
IEnumerator DownloadCSV()
{var www = new WWW("www.inter-illusion/mygame/localization.csv");yield return www;    // Wait for the file to be downloaded// Check for errors (url not found, no internet, etc)if (!string.IsNullOrEmpty(www.error)){Debug.LogWarning("Unable to download Localization data: " + www.error);yield break;}UseLocalizationCSV( www.text );
}

从本地存储读取。

void ReadCSVFrom_Resources()
{var asset = Resources.Load<TextAsset>( "localization.csv");// Check for errors (file not found)if (asset==null){Debug.LogWarning("Unable to load Localization data");return}UseLocalizationCSV( asset.text );
}// This approach is useful for letting the user modify the csv file
void ReadCSVFrom_StreamingFolder()
{try{var CSVstring = File.ReadAllText(Application.streamingAssetsPath + "/localization.csv");UseLocalizationCSV( CSVstring );}catch (System.Exception e){Debug.LogWarning("Unable to load Localization data");}
}

导入CSV内容。

void UseLocalizationCSV( string CSVfile )
{// Source[0] is the I2Languages.assetI2.Loc.LocalizationManager.Sources[0].Import_CSV( string.Empty, CSVfile, eSpreadsheetUpdateMode.Replace, ',');LocalizationManager.LocalizeAll();    // Force localing all enabled labels/sprites with the new data
}

参考
【unity插件】Unity多语言插件I2 Localization简单使用

【本地化超强插件】I2 Localization使用教学

官方教程(含API)

各国语言缩写

Unity学习笔记-I2 localization相关推荐

  1. Unity学习笔记(4)-----粒子效果的实现

    Unity学习笔记(4)-–粒子效果的实现 一.效果展示 下面用若干张张动图展示效果: 大概就是这样,并不是很难. 实际效果要比图中的好一点(顺畅得多). 实现步骤 大致可以分为如下几个步骤,然后逐个 ...

  2. Unity学习笔记1 简易2D横版RPG游戏制作(一)

    这个教程是参考一个YouTube上面的教程做的,原作者的教程做得比较简单,我先参考着做一遍,毕竟我也只是个初学者,还没办法完全自制哈哈.不过我之前也看过一个2D平台游戏的系列教程了,以后会整合起来,做 ...

  3. 【Unity学习笔记】[Unity中文课堂教程] C#中级编程代码

    [Unity学习笔记][Unity中文课堂教程] C#中级编程代码 最近想补一补C#基础,Unity官方的C#中级编程教程质量很高,于是开个帖子把跟着敲+记录了部分价讲解和我自己的理解的代码存在这 原 ...

  4. Unity学习笔记:个人学习项目《疯狂天才埃德加》纠错文档

    Unity学习笔记:个人学习项目<疯狂天才埃德加>纠错文档 本文档是完成学校Unity课程作业时建立的纠错文档.用于记录自己开发过程中遇到的各种问题,以便下次遇到相同的问题时及时找到解决方 ...

  5. Unity学习笔记:Unity 3D 飞机大战

    Unity学习笔记:Unity 3D 飞机大战 1.打开unity软件后,首先新建Quad作为背景,导入飞机模型,并为其添加刚体 然后创建C#脚本,挂载到飞机上. 2.给飞机创建子弹,让子弹成为预制体 ...

  6. 【Unity学习笔记】UnrealToUnity教程:(网上购买的素材导入Unreal+插件转Unity)

    [Unity学习笔记]UnrealToUnity教程: 最近想从Unreal那边化点缘借借素材,没想到踩到一个大坑 一,素材导入Unreal 这个教程比较多,根据素材的来源,传送门是以下这几个: 1. ...

  7. unity学习笔记-特效篇

    unity学习笔记 传送门特效 火焰特效 传送门特效 由于动画师的动画制作遇到了一些小问题,只能先做其他功能的摸索了~ 本来想记录一下服务器搭建的,但是在消息传输的部分遇到了一些bug,可能是消息解析 ...

  8. Unity学习笔记:监听函数有什么卵用?(似乎就是从一件事过渡到另一件事?)

    Unity学习笔记:监听函数有什么卵用?(似乎就是从一件事过渡到另一件事?) 个人学习经验,仅供参考,欢迎各位码友批评指正. 做项目敲代码时,一直不是很理解监听函数是个什么玩意. 按我目前的理解,说白 ...

  9. Unity学习笔记—二次元日系游戏制作(实践篇-游戏初始化场景制作)

    原教程:siki:二次元日系游戏制作工具 - live2dSDK入门教程 http://www.sikiedu.com/my/course/282 (上)Unity学习笔记-二次元日系游戏制作(理论篇 ...

最新文章

  1. ubuntu编译内核_鸿蒙源码下载并编译
  2. TriCore处理器的上下文切换原理
  3. 名创优品向港交所提交上市申请书
  4. fork、vfork、clone 三者的区别
  5. windows server 2012 r2 *** 服务器搭建
  6. 超级搜索术-朱丹-全部笔记整理
  7. torch.cat()函数用法
  8. 人工智能谓词逻辑——猴子摘香蕉问题
  9. 企业私有云存储选NAS还是私有云盘?3分钟带你了解企业NAS和企业云盘的区别
  10. 买不起MacBook,使用Windows 10配置zsh命令行做开发
  11. unity 代码拷贝材质球
  12. 定积分求解方法——换元积分法
  13. 那些主流的淘宝客引流方法有哪些?
  14. AirVO: An Illumination-Robust Point-Line Visual Odometry阅读
  15. 码农小汪-Volatile和Transient
  16. 【直击DTCC】安全行业的搜索引擎?白帽汇引爆新鲜感
  17. 利用快手抖音做小吃培训,年入100000+
  18. java中getDelta是什么意思_什么Delta编码/压缩算法库有Java?
  19. HTML表格标签,真香
  20. 串行数字接口(SDI)

热门文章

  1. root联通定制机顶盒,root 机顶盒
  2. springboot访问页面显示Whitelabel Error Page
  3. 常见的dataframe选取行列方式
  4. 般若堂--Spring Boot系列之参数校验
  5. 【数组】#66 加一
  6. 基础//页面布局——三栏布局1
  7. 利用Python批量将csv文件转化成xml文件
  8. linux键盘触摸板失灵,linux 中屏幕合上后触摸板无法使用
  9. PCB塞孔和不塞孔到底有什么区别,设计时如何选择塞孔还是不塞孔?
  10. 为什么说JCLGMP必将带来更实实在在的就学等方面权益?