๐ 2019.11.11 (์)
WWDC 2017 | Session : 401 | Category : Xcode
๐ Localizing with Xcode 9 - WWDC 2017 - Videos - Apple Developer
๊ท์ฅ๋ฐ
์ธ์ด๊ฐ ๊ธธ๋ ์งง๋, ์ค๋ฅธ์ชฝ์์ ์ผ์ชฝ์ผ๋ก ์ฐ๋, ๋์ ์ผ๋ก ์ด ๋ชจ๋ ์๋๋ฆฌ์ค์ ์ ์ฉํด์ผ ํ๋ค.
๋ฐํ์ ์ NSLocalizedString
์ ์ฌ์ฉํ๋ฉด ์๋ง๋ ๋ฒ์ญ ๋ ์ธ์ด๋ฅผ display ํ๋ ๊ฒ์ ์ฝ๊ฒ ๋ง๋ค์ด ์ค๋ค.
Storyboard ๋ zip ํ์ผ์ ์๋ String์ default๋ก ํ์งํ ํ ์ ์๋ค.
ํ์ง๋ง ์๋ฌ ๋ฉ์ธ์ง๋ notification ๊ฐ์ ์์ค ์ฝ๋์ ์ ์ ๋์ด ์๋ String๋ ์์ ์ ์๋ค. ์ด String๋ค์ NSLocalizedStringForm
์ผ๋ก ๊ฐ์ธ๋ฉด ๋๋ค.
NSLocalizedWithFormat
์ผ๋ก formatted string์ ์ฌ์ฉ ํ ์ ์๋ค.
// Set a label's text
label.text = "Population"
// Set a label's text to a localized string
label.text = NSLocalizedString("Population", comment: "Label preceding the population value")
// Load localized string from a specific table
label.text = NSLocalizedString("Poluation", tableName: "Localizable", bundle: .main, value: nil, comment: "Label preceding the population value")
// Create a formatted string
let format = NSLocalizedString("%d popular languages, comment: "Number of popular languages")
label.text = String.localizedStrinWithFormat(format, popularLanguages.count)
comment โ ๋ฒ์ญ ๋ string์ ๋ํ ๋งฅ๋ฝ ์ ๊ณต
tableName โ framework๋ shared component๋ฅผ ์ฌ์ฉ ์ ์ถ์ฒ๋ฅผ ์ํด tableName ์ฌ์ฉ
localizedStringWithFormat
format ๋๋ String ์ธ์ง ํ๊ธฐ ์ํด ๋ฌธ๋งฅ ํ์
ํด์ผ ํจ
fb.Iproj/Localizeable.string
/* Title label's text */
"International Facts" = "Faits Internationaux";
/* Label prompting a user to choose a territory */
"Territory" = "Territoire";
๋ฐํ์ ์, NSLocalizedString
์ ์ ์ ์ ์ ํธ language๋ฅผ ๊ฒฐ์ ํ๊ณ , localized string file์ ์ฐพ์ ๊ฒ์ด๋ค.
๋ ์ง, ์๊ฐ, ์ซ์ ๋ฑ์ ๋ํ ๋ค๋ฅธ ์๊ฐ์ ์ธ ํํ์ ๋ํ ์ง์ญํ
๋ชจ๋ ์ธ์ด์์ UI๊ฐ flexibleํด์ผ ํ๊ณ niceํด ๋ณด์ฌ์ผ ํ๋ค.
- Xcode๊ฐ Destructor์ ์ํด ํ๋ก์ ํธ๋ฅผ ์์ ํ ๊ฒ์ด๋ค.
- ๊ทธ๋ฆฌ๊ณ UI๋ฅผ String์ผ๋ก ๋ถํฐ ๋ถ๋ฆฌ ํ ๊ฒ์ด๋ค. โ User Interface์ ๊ด๋ จ ๋ ํ์ผ์(zip ํ์ผ์ด๋ storyboardํ์ผ ๊ฐ์)
Base.lproj
์ ์ ์ฅ ๋ ๊ฒ์ด๋ค - ์คํ ๋ฆฌ๋ณด๋ ํ์ผ์ด๋
NSLocalizedString
์ ํตํด์ unwrap ๋ String์ ํน์ ์ธ์ด ํด๋์ ์ ์ฅ ๋ ๊ฒ์ด๋ค. โ ์ฑ์ ์๋ก์ด ์ธ์ด๋ฅผ ๋ง๋ค ๋ ๋ง๋ค, ๋ณต์ฌํ๋ ๋์ ์ User Interface์ ํ๋์ ํน์ ์ธ์ด ํด๋๋ฅผ ๊ฐ์ง๊ณ ์๋๋ก - base internationalization์ Xcode 5๋ถํฐ default๋ก ๊ฐ๋ฅ ํ๋ค.
๐ Localization warnings โ localization์ ๊ณ ๋ ค ํ์ง ์์ constraint์ warning
๐ Pseudolocalization ์ธ์ด ๋ง๋ค ํน์ง์ ์ ์ฉํด์ ๋ฏธ๋ฆฌ ๋ณผ ์ ์์
- Use standard APIs to handle the complexity of data formatting
- User base internationalization and Auto Layout
- Validate your strings and UI
- Xcode๋ ํ๋ก์ ํธ์ ๋ชจ๋ localizable resource๋ฅผ ์ฐพ์์,
- ํ๋ก์ ํธ๊ฐ localization ์ ์ํด export ๋ ๋, Xcode๋ localizable resource๋ค๋ก ๋ถํฐ string์ ์ถ์ถํด์ ๋น์ ์ด ์ถ๊ฐํ ๋ชจ๋ ์ธ์ด์ ๋ํ XLIFF ํ์ผ์ ์์ฑ ํ ๊ฒ์ด๋ค
- XLIFF ํ์ผ์ localization ์ฐ์ ์์ ํ์ค standard XML localization file์ด๋ค.
- localizer ์ค ํ๋์๊ฒ XLIFF ํ์ผ์ ๋ณด๋ด๋ฉด, ์ด๋ฏธ ํฌ๋งท๊ณผ ์ฌ์ฉ๋ฒ์ ๋ํด ์น์ ํ ๊ฒ์ด๋ค.
- ์ผ๋จ XLIFF ํ์ผ์ด ๋ฒ์ญ ๋๋ฉด Xcode์ import ํ ์ ์๊ณ ์๋์ผ๋ก localized text์ ํตํฉ ๋ ๊ฒ์ด๋ค
โ ์ด๊ฒ์ด Xcode ์ localization ํ๋ ๊ณผ์ ์ด๋ค. ๋งค์ฐ ๊ฐ๋จํ๊ณ ์ง๊ด์ ์ด๋ค.
๐ Stringdict
Xcode9์์ String dic format์ String์ export, import์ ๋ํ ์ง์์ ์ถ๊ฐ ํ๋ค.
๐ Adaptive Strings
- Use strings dict for plurals and width variants
- Export XLIFF for localization
- Import localized XLIFF
- Localize non-string resources in Xcode
XCTest
์ ์ฝ๋๋ localization์ด ์๋๊ณ , ํ ์คํธ๋ฅผ ์คํํ๋ ๊ฐ๊ฐ์ ์ธ์ด๋ก ๋ฒ์ญ ๋ ๊ฒ์ด๋ค
accessibilityIdentifier
์ ์ฌ์ฉํ๋ฉด ํ๋ฉด์ ๋ชจ๋ element์ ๊ณ ์ ํ๊ณ , ํด๋น element์ ์ด๋ค string์ด load ๋๋์ง ๋ชจ๋ฅธ์ฑ ์ฌ์ฉ ํ ์ ์๋ค.
Set accessibilityIdentifier
button.accessibilityIdentifier = "startButton"
- Use accessibility identifiers
- Use
XCTAttachment
to collect screenshots - Get full coverage of UI for all localizations
- Prepare your app for localization
- Validate your app's readiness
- Export localizable content to be translated
- Import localized content
- User
XCTest
to test your localized app