×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2012.741 | Released: 7 Feb 2012, 8:45am | What's New | Download Now

Hello World - Localized

Features demonstrated:

Language support, textfields, default system font.

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
local translations =
{
        ["en"] = "Hello, world!",
        ["fr"] = "Bonjour, le monde!",
        ["pt"] = "Olá mundo!",
        ["zh-Hant"] = "世界你好!",
        ["zh-Hans"] = "世界你好!",
        ["de"] = "Hallo, Welt!",
        ["it"] = "Salve, mondo!",
        ["ja"] = "世界よ、こんにちは!",
        ["es"] = "¡Hola mundo!",
}
 
local language = "en"
 
local os = system.getInfo("platformName")
if os == "Android" then
        print( "system.getPreference is not implemented on Android yet" )
else
        language = system.getPreference( "ui", "language" )
end
 
-- Other localization-related system properties:
--  system.getPreference( "locale", "country" )
--  system.getPreference( "locale", "identifier" )
--  system.getPreference( "locale", "language" )
 
local message = translations[language]
if not message then
        -- default to English
        message = translations.en
end
 
-- Background image from NASA's Visible Earth gallery (http://visibleearth.nasa.gov/)
local background = display.newImage("globe_east.png")
 
-- Show text, using default bold font of device (works in iOS or Android)
local textObject = display.newText( message, 0, 0, native.systemFontBold, 24 )
textObject:setTextColor( 255,255,255 )
 
-- A trick to get text to be centered
local centeredGroup = display.newGroup()
centeredGroup.x = display.contentWidth * 0.5
centeredGroup.y = display.contentHeight * 0.5
centeredGroup:insert( textObject, true )
 
-- Insert rounded rect behind textObject
local r = 10
local roundedRect = display.newRoundedRect( 0, 0, textObject.stageWidth + 2*r, textObject.stageHeight + 2*r, r )
roundedRect:setFillColor( 55, 55, 55, 190 )
centeredGroup:insert( 1, roundedRect, true )
   

AttachmentSize
HelloWorld2.zip50.78 KB