23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1. Create a strings folder in the root of your app project.<br />

2. Within that folder, create a subfolder that matches the BCP-47 language tag specified as the<br />

default language in the manifest (for example, en-US, fr-FR, ja-JP, or just the base language like<br />

en or ru).<br />

3. Move your resources.resjson file into that folder.<br />

If you run your app again at this point, you should see that everything still works. If you go back to<br />

the How to name resources using qualifiers topic we mentioned earlier, you’ll see that the resource<br />

loader is perfectly happy when you use qualifiers like a BCP-47 name as a folder name. It basically parses<br />

entire folder names looking for qualifiers, so you can create deep hierarchies to sort your resources<br />

however you like. That is, you can sort by contrast or scale first, if desired, and include language suffixes<br />

in the filename (where the format is lang-). What’s more, you can create secondary<br />

.resjson files in these folders as well and play some other tricks. See “Sidebar: Secondary String Resource<br />

Files” for details.<br />

Anyway, what you’ve just done by moving your resources into a folder for your default language is<br />

set your fallback language resources—this is what the resource loader will turn to if it cannot find a<br />

more specific match for the user’s current language. Finding a match is actually a sophisticated process<br />

wherein the resource loader measures a kind of “distance” between the user’s preferences and the<br />

available resources and chooses whichever is closest. This makes it possible to select en-GB as a closer<br />

match to en-AU than en-US, for example. Generally, though, it means that the resource loaded will<br />

search for a specific match like de-DE (German) first, then the next closest language using the base<br />

qualifier de, and then eventually fall back to your default language (if there are no resources for the<br />

user’s other languages). The short of it is that you should always make sure the language identified in<br />

your manifest is fully populated with your full set of resources! Then even if you don’t happen to localize<br />

some of those resources (say, for exact cultural alignment with images), one will still be found. For the<br />

complete story on this subject, refer to Language Matching in the documentation.<br />

Sidebar: Secondary String Resource Files<br />

Both WinRT and WinJS are able to work with secondary string resource (.resjson) files, allowing<br />

you to organize your strings in multiple files, if desired. For example, it’s common to separate<br />

error strings into a file called errors.resjson. When referencing a string identifier in one of these<br />

secondary files, all that’s needed is that you use the syntax // instead of just<br />

. This syntax works in <strong>HTML</strong>, JavaScript, and the app manifest. See Scenario 5 of the<br />

Application resources and localization sample for an example.<br />

Something else you can do with .resjson files is name them with other qualifiers for contrast,<br />

scale, home region, and so forth and even organize those files under any old folder. This is<br />

demonstrated in Scenario 13 of the same sample, where it has many different .resjson files<br />

underneath strings/scenario13, each of which is named as scenario13..resjson. Because<br />

814

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!