Setting the Map language in the Maps API for Java ME
trashedDev
(Talk | contribs) (TrashedDev -) |
m (Jasfox - Added localisation tip.) |
||
| (19 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
| − | [[Category:Nokia Maps]][[Category:Code Snippet]][[Category:Java ME]] | + | [[Category:Nokia Maps]][[Category:Code Snippet]][[Category:Java ME]][[Category:Series 40]][[Category:Symbian]][[Category:Series 40 Developer Platform 2.0]][[Category:Series 40 6th Edition FP1]][[Category:Series 40 Developer Platform 1.1]][[Category:Series 40 Developer Platform 2.0]] |
{{Abstract|This article explains how to alter the''' map language''' of a Java ME application }} | {{Abstract|This article explains how to alter the''' map language''' of a Java ME application }} | ||
{{ArticleMetaData | {{ArticleMetaData | ||
|sourcecode= [[Media:MapLanguageMIDlet.zip | Map Language MIDlet Source]]<!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] --> | |sourcecode= [[Media:MapLanguageMIDlet.zip | Map Language MIDlet Source]]<!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] --> | ||
| − | <!-- | + | |installfile= [[Media:MapLanguageMIDletBinaries.zip | Map Language MIDlet Binaries]]<!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> |
| − | |devices=X3-02 | + | |devices=X3-02, Asha 305 |
| − | |sdk=[http://www.developer.nokia.com/Develop/Java/ Nokia SDK 1.0 for Java] | + | |sdk=[http://www.developer.nokia.com/Develop/Java/ Nokia SDK 1.0 for Java], [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 2.0 for Java (beta)] |
| − | |dependencies= [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] v1. | + | |dependencies= [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] v1.1 |
|platform=S40, Symbian^1, Symbian^3 | |platform=S40, Symbian^1, Symbian^3 | ||
|devicecompatability=All | |devicecompatability=All | ||
| Line 22: | Line 22: | ||
* [[Implementing a custom MapUrlProvider overlay with Maps API for Java ME|Implementing a custom MapUrlProvider overlay]] | * [[Implementing a custom MapUrlProvider overlay with Maps API for Java ME|Implementing a custom MapUrlProvider overlay]] | ||
* [[How to create custom Map View in Java ME|How to create custom Map View]] | * [[How to create custom Map View in Java ME|How to create custom Map View]] | ||
| + | * [[Localising app attributes in Java ME|Localising app attributes]] | ||
}} | }} | ||
== Introduction == | == Introduction == | ||
| − | By default all the maps in the [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Map API for Java ME] will display in '''English'''. The API is able to support a variety of other languages | + | By default all the maps in the [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Map API for Java ME] will display in '''English'''. The API is however able to support a variety of other languages. The language used to display labels on the map is set in the ''ApplicationContext'', and this should be done prior to displaying the map itself. The {{Icode|setDefaultLanguage()}} method takes a three letter [http://www.loc.gov/marc/languages/language_code.html MARC Code]. If an unsupported language is requested, the map will display in English by default. |
| + | |||
| + | {{Tip| It is possible to obtain the default language of the '''phone''' by requesting the {{Icode|"microedition.locale"}} system property. | ||
| + | <Code language=java>System.getProperty("microedition.locale");</Code>This will retrieve a two letter MARC Code, which can be mapped onto a three letter MARC code using a simple {{Icode|switch}} statement. Alternatively a locallized three letter MARC code could be [[Localising app attributes in Java ME|read from the JAD file]] | ||
| + | }} | ||
Examples of usable MARC codes include: | Examples of usable MARC codes include: | ||
| Line 36: | Line 41: | ||
* '''RUS''' Russian | * '''RUS''' Russian | ||
* '''SPA''' Spanish | * '''SPA''' Spanish | ||
| − | |||
==Implementation== | ==Implementation== | ||
Revision as of 10:29, 14 August 2012
This article explains how to alter the map language of a Java ME application
Article Metadata
Code Example
Tested with
Compatibility
Article
Introduction
By default all the maps in the Map API for Java ME will display in English. The API is however able to support a variety of other languages. The language used to display labels on the map is set in the ApplicationContext, and this should be done prior to displaying the map itself. The setDefaultLanguage() method takes a three letter MARC Code. If an unsupported language is requested, the map will display in English by default.
Invalid language.
You need to specify a language like this: <source lang="html4strict">...</source>
Supported languages for syntax highlighting:
4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic
System.getProperty("microedition.locale");This will retrieve a two letter MARC Code, which can be mapped onto a three letter MARC code using a simple switch statement. Alternatively a locallized three letter MARC code could be read from the JAD fileExamples of usable MARC codes include:
- ARA Arabic
- CHI Chinese
- GER German
- ENG English
- FRE French
- ITA Italian
- RUS Russian
- SPA Spanish
Implementation
This is a simple example of a minimal map which will display in one of eight random languages.
public class MapLanguageMIDlet extends MIDlet {
protected void startApp() throws MIDletStateChangeException {
// Please initialise the appId and token first
ApplicationContext ctx = ApplicationContext.getInstance();
ctx.setAppID("MyAppId");
ctx.setToken("MyToken");
Display display = Display.getDisplay(this);
MapLanguageDemo minimalMap = new MapLanguageDemo(display, this);
display.setCurrent(minimalMap);
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {}
protected void pauseApp() {}
}
public class MapLanguageDemo extends MapCanvas implements CommandListener {
private final Command EXIT = new Command("Exit", Command.EXIT, 1);
private final static String[] MARC_CODES = {"ARA", "CHI", "GER", "ENG",
"FRE", "ITA", "RUS", "SPA"
};
private final static String[] LANGUAGES = {"Arabic", "Chinese", "German", "English",
"French", "Italian", "Russian", "Spanish"
};
protected MIDlet midlet;
public MapLanguageDemo(Display display, MIDlet midlet) {
super(display);
this.midlet = midlet;
init();
}
private void init() {
addCommand(EXIT);
Random r = new Random();
int i = r.nextInt(LANGUAGES.length);
ApplicationContext.getInstance().setDefaultLanguage(MARC_CODES[i]);
setTitle(LANGUAGES[i]);
setCommandListener(this);
// Set map over Europe.
map.setState(
new MapDisplayState(new GeoCoordinate(53.1, 13.1, 0), 4));
}
public void commandAction(final Command c, Displayable d) {
if (c == EXIT) {
midlet.notifyDestroyed();
}
}
public void onMapUpdateError(String description, Throwable detail, boolean critical) {
Alert alertView = new Alert("Map error: ", detail.getMessage(), null, AlertType.ERROR);
display.setCurrent(alertView);
}
public void onMapContentComplete() {
}
}
Example Output
| Chinese | Russian | Arabic |
|---|---|---|
| |
|
|

