background preloader

i18n

Facebook Twitter

Internationalization - Android: I18n with parameters. Android XML Percent Symbol. Context. Register a BroadcastReceiver to be run in the main activity thread.

Context

The will be called with any broadcast Intent that matches , in the main application thread. The system may broadcast Intents that are "sticky" -- these stay around after the broadcast as finished, to be sent to any later registrations. If your IntentFilter matches one of these sticky Intents, that Intent will be returned by this function and sent to your as if it had just been broadcast. There may be multiple sticky Intents that match , in which case each of these will be sent to . In this case, only one of these can be returned directly by the function; which of these that is returned is arbitrarily decided by the system. If you know the Intent your are registering for is sticky, you can supply null for your . See BroadcastReceiver for more information on Intent broadcasts. Formatter. Formats arguments according to a format string (like printf in C).

Formatter

Format strings consist of plain text interspersed with format specifiers, such as "name: %s weight: %03dkg\n". Being a Java string, the usual Java string literal backslash escapes are of course available. Format specifiers (such as "%s" or "%03d" in the example) start with a % and describe how to format their corresponding argument. It includes an optional argument index, optional flags, an optional width, an optional precision, and a mandatory conversion type. In the example, "%s" has no flags, no width, and no precision, while "%03d" has the flag 0, the width 3, and no precision. Not all combinations of argument index, flags, width, precision, and conversion type are valid. Argument index.

Flags. Width. Precision. Conversion type. This table shows the available single-character (non-date/time) conversion types: This table shows the date/time conversions, but you should use SimpleDateFormat instead: Localization. Android will run on many devices in many regions.

Localization

To reach the most users, your application should handle text, audio files, numbers, currency, and graphics in ways appropriate to the locales where your application will be used. This document describes best practices for localizing Android applications. The principles apply whether you are developing your application using ADT with Eclipse, Ant-based tools, or any other IDE.

You should already have a working knowledge of Java and be familiar with Android resource loading, the declaration of user interface elements in XML, development considerations such as Activity lifecycle, and general principles of internationalization and localization. It is good practice to use the Android resource framework to separate the localized aspects of your application as much as possible from the core Java functionality: For a short guide to localizing strings in your app, see the training lesson, Supporting Different Languages. Example: Localization Checklist. La gestion des strings sous Android. Dans ce tutoriel nous allons aborder la gestion des chaines de caractères sous Android.

La gestion des strings sous Android

Les strings servent à référencer des chaines de caractères que vous allez utiliser dans votre application. Création de chaines de caractéres Le fichier qui contiendra vos chaines de caractères ne doit pas forcement se nommer strings.xml. Vous pouvez lui donner le nom que vous souhaité, il doit seulement se trouver dans le dossier values et entre des balises &ltstring&gt. Voici un petit exemple <? Vous pouvez utiliser une chaîne que vous avez déclaré depuis : Un fichier Java : R.string.nom_string Un fichier Xml : @string/nom_string Gestion du pluriel Pour vous permettre de gérer le pluriel de vos chaines de caractères, android intègre une balise très pratique (plurals).

Voici un petit exemple : <? L’attribut quantité peut avoir les valeurs suivantes : Pour pouvoir récupérer ces chaines de caractéres en Java, la méthode getQuantityString est disponible. public String getQuantityString(int id, int quantity); <?