https://www.droidwiki.org/w/index.php?title=Android_Training/Supporting_Different_Languages/en&feed=atom&action=historyAndroid Training/Supporting Different Languages/en - Versionsgeschichte2024-03-29T15:22:11ZVersionsgeschichte dieser Seite in Android WikiMediaWiki 1.41.0-wmf.5https://www.droidwiki.org/w/index.php?title=Android_Training/Supporting_Different_Languages/en&diff=13641&oldid=prevFuzzyBot: Neue Version von externer Quelle importiert2015-12-24T17:20:27Z<p>Neue Version von externer Quelle importiert</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="de">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Nächstältere Version</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Version vom 24. Dezember 2015, 18:20 Uhr</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l5">Zeile 5:</td>
<td colspan="2" class="diff-lineno">Zeile 5:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== Create Locale Directories and String Files ==</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== Create Locale Directories and String Files ==</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>To add support for more languages, create additional <code>values</code> directories inside <code>res/</code> that include a hyphen and the ISO language code at the end of the directory name. For example, <code>values-es/</code> is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time. For more information, see [http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources Providing Alternative <del style="font-weight: bold; text-decoration: none;">Resource</del>]<del style="font-weight: bold; text-decoration: none;">s</del>.</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>To add support for more languages, create additional <code>values</code> directories inside <code>res/</code> that include a hyphen and the ISO language code at the end of the directory name. For example, <code>values-es/</code> is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time. For more information, see [http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources Providing Alternative <ins style="font-weight: bold; text-decoration: none;">Resources</ins>].</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example:</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example:</div></td></tr>
</table>FuzzyBothttps://www.droidwiki.org/w/index.php?title=Android_Training/Supporting_Different_Languages/en&diff=13634&oldid=prevFuzzyBot: Neue Version von externer Quelle importiert2015-12-24T14:26:59Z<p>Neue Version von externer Quelle importiert</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="de">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Nächstältere Version</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Version vom 24. Dezember 2015, 15:26 Uhr</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l2">Zeile 2:</td>
<td colspan="2" class="diff-lineno">Zeile 2:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>It’s always a good practice to extract UI strings from your app code and keep them in an external file. Android makes this easy with a resources directory in each Android project.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>It’s always a good practice to extract UI strings from your app code and keep them in an external file. Android makes this easy with a resources directory in each Android project.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>If you created your project using the Android SDK Tools (<del style="font-weight: bold; text-decoration: none;">readCreating </del>an Android Project), the tools create a <code>res/</code> directory in the top level of the project. Within this <code>res/</code> directory are subdirectories for various resource types. There are also a few default files such as <code>res/values/strings.xml</code>, which holds your string values.</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>If you created your project using the Android SDK Tools (<ins style="font-weight: bold; text-decoration: none;">read [[Special:MyLanguage/Android_Training/Creating_an_Android_Project|Creating </ins>an Android Project<ins style="font-weight: bold; text-decoration: none;">]]</ins>), the tools create a <code>res/</code> directory in the top level of the project. Within this <code>res/</code> directory are subdirectories for various resource types. There are also a few default files such as <code>res/values/strings.xml</code>, which holds your string values.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== Create Locale Directories and String Files ==</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== Create Locale Directories and String Files ==</div></td></tr>
<!-- diff cache key droidwikiwiki:diff::1.12:old-13486:rev-13634 -->
</table>FuzzyBothttps://www.droidwiki.org/w/index.php?title=Android_Training/Supporting_Different_Languages/en&diff=13486&oldid=prevFuzzyBot: Neue Version von externer Quelle importiert2015-12-21T01:51:16Z<p>Neue Version von externer Quelle importiert</p>
<p><b>Neue Seite</b></p><div><languages /><br />
It’s always a good practice to extract UI strings from your app code and keep them in an external file. Android makes this easy with a resources directory in each Android project.<br />
<br />
If you created your project using the Android SDK Tools (readCreating an Android Project), the tools create a <code>res/</code> directory in the top level of the project. Within this <code>res/</code> directory are subdirectories for various resource types. There are also a few default files such as <code>res/values/strings.xml</code>, which holds your string values.<br />
<br />
== Create Locale Directories and String Files ==<br />
To add support for more languages, create additional <code>values</code> directories inside <code>res/</code> that include a hyphen and the ISO language code at the end of the directory name. For example, <code>values-es/</code> is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time. For more information, see [http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources Providing Alternative Resource]s.<br />
<br />
Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example:<br />
<syntaxhighlight lang="text"><br />
MyProject/<br />
res/<br />
values/<br />
strings.xml<br />
values-es/<br />
strings.xml<br />
values-fr/<br />
strings.xml<br />
</syntaxhighlight><br />
<br />
Add the string values for each locale into the appropriate file.<br />
<br />
At runtime, the Android system uses the appropriate set of string resources based on the locale currently set for the user's device.<br />
<br />
For example, the following are some different string resource files for different languages.<br />
<br />
English (default locale), <code>/values/strings.xml</code>:<syntaxhighlight lang="xml"><br />
<?xml version="1.0" encoding="utf-8"?><br />
<resources><br />
<string name="title">My Application</string><br />
<string name="hello_world">Hello World!</string><br />
</resources><br />
</syntaxhighlight><br />
<br />
Spanish, <code>/values-es/strings.xml</code>:<syntaxhighlight lang="xml"><br />
<?xml version="1.0" encoding="utf-8"?><br />
<resources><br />
<string name="title">Mi Aplicación</string><br />
<string name="hello_world">Hola Mundo!</string><br />
</resources><br />
</syntaxhighlight><br />
<br />
French, <code>/values-fr/strings.xml</code>:<syntaxhighlight lang="xml"><br />
<?xml version="1.0" encoding="utf-8"?><br />
<resources><br />
<string name="title">Mon Application</string><br />
<string name="hello_world">Bonjour le monde !</string><br />
</resources><br />
</syntaxhighlight><br />
<br />
'''Note:''' You can use the locale qualifier (or any configuration qualifer) on any resource type, such as if you want to provide localized versions of your bitmap drawable. For more information, see [http://developer.android.com/guide/topics/resources/localization.html Localization].<br />
<br />
== Use the String Resources ==<br />
You can reference your string resources in your source code and other XML files using the resource name defined by the <code><string></code> element's <code>name</code> attribute.<br />
<br />
In your source code, you can refer to a string resource with the syntax <code>R.string.<string_name></code>. There are a variety of methods that accept a string resource this way.<br />
<br />
For example:<br />
<syntaxhighlight lang="java"><br />
// Get a string resource from your app's Resources<br />
String hello = getResources().getString(R.string.hello_world);<br />
<br />
// Or supply a string resource to a method that requires a string<br />
TextView textView = new TextView(this);<br />
textView.setText(R.string.hello_world);<br />
</syntaxhighlight><br />
<br />
In other XML files, you can refer to a string resource with the syntax <code>@string/<string_name></code> whenever the XML attribute accepts a string value.<br />
<br />
For example:<br />
<syntaxhighlight lang="xml"><br />
<TextView<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:text="@string/hello_world" /><br />
</syntaxhighlight><br />
<br />
{{TNT|Android Training/Attribution}}</div>FuzzyBot