코로나 SDK 다국어 지원 개발 방법



Corona SDK: Localization made easy

Andre Biasi

Are you trying to reach international markets? Here's a handy tip to make the whole process easier with Corona SDK.

First we start by creating a file called translations.lua, which we’ll use to store all the localized text strings used in the app. Here’s an example of how it should look like:

  1. -- translations.lua
  2.  
  3. local translations =
  4. {
  5. ["Hello"] =
  6. {
  7. ["en"] = "Hello",
  8. ["fr"] = "Salut",
  9. ["de"] = "Hallo",
  10. ["es"] = "Hola",
  11. ["it"] = "Ciao"
  12. },
  13. ["World"] =
  14. {
  15. ["en"] = "world",
  16. ["fr"] = "monde",
  17. ["de"] = "Welt",
  18. ["es"] = "mundo",
  19. ["it"] = "mondo"
  20. },
  21. ["Hello world"] =
  22. {
  23. ["en"] = "Hello world",
  24. ["fr"] = "Bonjour tout le monde",
  25. ["de"] = "Hallo Welt",
  26. ["es"] = "Hola mundo",
  27. ["it"] = "Ciao a tutti"
  28. }
  29. }
  30.  
  31. return translations

As you can see, it’s a LUA table using the brackets syntax with a list of words or sentences that are also tables containing an entry per language supported. Brackets syntax is a must if the words or sentences contain special characters, which is 99.9% of the time when dealing with multiple languages. Let translators work on this file and the app gets localized automatically.

Here’s how to get it working inside your main.lua:

  1. -- main.lua
  2.  
  3. -- Load translations module locally
  4. local translations = require("translations")
  5.  
  6. -- Get the user's defined language (if any) or the device's default language
  7. local language = userDefinedLanguage or system.getPreference("ui", "language")
  8.  
  9. -- Other localization-related system properties:
  10. -- system.getPreference("locale", "country")
  11. -- system.getPreference("locale", "identifier")
  12. -- system.getPreference("locale", "language")
  13.  
  14. -- Create our text object
  15. local myText = display.newText(translations["Hello world"][language], 0, 0, native.systemFont, 16)

The function system.getPreference(“ui”, “language”) returns the ISO 639-1 language designation code and the ISO 3166-1 regional designation code if there’s any. For example “en” for English and “en-GB” for English (Great Britain). Make sure you use those codes in the table or it will fail.

When using the Director class, load the module globally in main.lua (without the “local” word) or locally in each Director scene (inside the new() function).

This method is not limited to 1 file or to that particular table structure. Multiple files or a more advanced table structure could be used to store the strings from different areas of the app like the main menu, help screen and so on.

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

One last thing that’s worth mentioning from the iOS Developer Library is the following key that can be added to the build.settings file:

CFBundleLocalizations (Array – iOS, Mac OS X) identifies the localizations handled manually by your application. If your executable is unbundled or does not use the existing bundle localization mechanism, you can include this key to specify the localizations your application does handle. Each entry in this property’s array is a string identifying the language name or ISO language designator of the supported localization.

Basically, this key will enable the iTunes App Store to advertise the languages supported by your Corona SDK app in the info panel. Here’s an example:

  1. -- build.settings
  2.  
  3. settings =
  4. {
  5. iphone =
  6. {
  7. plist=
  8. {
  9. CFBundleLocalizations =
  10. {
  11. "English",
  12. "French",
  13. "German",
  14. "Italian",
  15. "Spanish"
  16. },
  17. },
  18. },
  19. }

- See more at: http://www.monkeybin.com/blog/archives/2011/09/18/corona-sdk-localization-made-easy/#sthash.XzwoXxMV.dpuf


[출처] http://www.monkeybin.com/blog/archives/2011/09/18/corona-sdk-localization-made-easy/







본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED