Dealing with Locale


A locale represents a specific geographical, political, or cultural region. Numbers and dates are considered locale-sensitive , so number formats are associated with a locale. Use Tools Options Language Settings Languages to see which locale is used for your computer. Creating a locale is very easy.

 Dim aLocale As New com.sun.star.lang.Locale aLocale.Language = "fr" aLocale.Country = "FR" 
Note  

OOo may not support every possible locale, but it will attempt to use the best possible match.

The locale depends upon both the language and the country. Some countries use multiple languages and some languages are used in multiple countries . Table 12 contains the two-character code that identifies each language, and Table 13 contains the two-character code that identifies each country.

Table 12: Locale language codes, alphabetized by code.

Code

Language

aa

Afar

am

Amharic

ay

Aymara

be

Byelorussian

bi

Bislama

br

Breton

cs

Czech

ab

Abkhazian

ar

Arabic

az

Azerbaijani

bg

Bulgarian

bn

Bengali; Bangla

ca

Catalan

cy

Welsh

af

Afrikaans

as

Assamese

ba

Bashkir

bh

Bihari

bo

Tibetan

co

Corsican

da

Danish

de

German

en

English

et

Estonian

fi

Finnish

fr

French

gd

Scots Gaelic

gu

Gujarati

hi

Hindi

hy

Armenian

ie

Interlingue

it

Italian

jw

Javanese

kl

Greenlandic

ko

Korean

ky

Kirghiz

lo

Laothian

mg

Malagasy

ml

Malayalam

mr

Marathi

my

Burmese

nl

Dutch

om

(Afan) Oromo

pl

Polish

qu

Quechua

ro

Romanian

sa

Sanskrit

sh

Serbo-Croatian

sl

Slovenian

so

Somali

ss

Siswati

sw

Swahili

tg

Tajik

tk

Turkmen

to

Tonga

tt

Tatar

uk

Ukrainian

vi

Vietnamese

xh

Xhosa

za

Zhuang

dz

Bhutani

eo

Esperanto

eu

Basque

fj

Fiji

fy

Frisian

gl

Galician

ha

Hausa

hr

Croatian

ia

Interlingua

ik

Inupiak

iu

Inuktitut

ka

Georgian

km

Cambodian

ks

Kashmiri

la

Latin

It

Lithuanian

mi

Maori

mn

Mongolian

ms

Malay

na

Nauru

no

Norwegian

or

Oriya

ps

Pashto, Pushto

rm

Rhaeto-Romance

ru

Russian

sd

Sindhi

si

Sinhalese

sm

Samoan

sq

Albanian

st

Sesotho

ta

Tamil

th

Thai

tl

Tagalog

tr

Turkish

tw

Twi

ur

Urdu

vo

Volapuk

yi

Yiddish (formerly ji)

zh

Chinese

el

Greek

es

Spanish

fa

Persian

fo

Faroese

ga

Irish

gn

Guarani

he

Hebrew (formerly iw)

hu

Hungarian

id

Indonesian (formerly in)

is

Icelandic

ja

Japanese

kk

Kazakh

kn

Kannada

ku

Kurdish

In

Lingala

Iv

Latvian, Lettish

mk

Macedonian

mo

Moldavian

mt

Maltese

ne

Nepali

oc

Occitan

pa

Punjabi

pt

Portuguese

rn

Kirundi

rw

Kinyarwanda

sg

Sangho

sk

Slovak

sn

Shona

su

Sundanese

sv

Swedish

te

Telugu

ti

Tigrinya

tn

Setswana

ts

Tsonga

ug

Uighur

uz

Uzbek

wo

Wolof

yo

Yoruba

zu

Zulu

Table 13: Locale country codes, capitalized by country.

Code

Country

AF

Afghanistan

DZ

Algeria

AD

Andorra

AI

Anguilla

AG

Antigua and Barbuda

AM

Armenia

AU

Australia

AZ

Azerbaijan

BH

Bahrain

BB

Barbados

BE

Belgium

BJ

Benin

BT

Bhutan

BA

Bosnia and Herzegowina

BV

Bouvet Island

IO

British Indian Ocean Territory

BG

Bulgaria

BI

Burundi

CM

Cameroon

CV

Cape Verde

CF

Central African Republic

CL

Chile

CX

Christmas Island

CO

Colombia

CD

Congo, Democratic Republic of (was Zaire)

CK

Cook Islands

CI

Cote D'lvoire

CU

Cuba

CZ

Czech Republic

DJ

Djibouti

DO

Dominican Republic

EC

Ecuador

SV

El Salvador

ER

Eritrea

ET

Ethiopia

FO

Faroe Islands

FI

Finland

FX

France, Metropolitan

PF

French Polynesia

GA

Gabon

GE

Georgia

GH

Ghana

GR

Greece

AL

Albania

AS

American Samoa

AO

Angola

AQ

Antarctica

AR

Argentina

AW

Aruba

AT

Austria

BS

Bahamas

BD

Bangladesh

BY

Belarus

BZ

Belize

BM

Bermuda

BO

Bolivia

BW

Botswana

BR

Brazil

BN

Brunei Darussalam

BF

Burkina Faso

KH

Cambodia

CA

Canada

KY

Cayman Islands

TD

Chad

CN

China

CC

Cocos (Keeling) Islands

KM

Comoros

CG

Congo, People's Republic of

CR

Costa Rica

HR

Croatia (local name : Hrvatska)

CY

Cyprus

DK

Denmark

DM

Dominica

TL

East Timor

EG

Egypt

GQ

Equatorial Guinea

EE

Estonia

FK

Falkland Islands (Malvinas)

FJ

Fiji

FR

France

GF

French Guiana

TF

French Southern Territories

GM

Gambia

DE

Germany

GI

GibraItar

GL

Greenland

GD

Grenada

GU

Guam

GN

Guinea

GY

Guyana

HM

Heard and Mc Donald Islands

HK

Hong Kong

IS

Iceland

ID

Indonesia

IQ

Iraq

IL

Israel

JM

Jamaica

JO

Jordan

KE

Kenya

KP

Korea, Democratic People's Republic Of

KW

Kuwait

LA

Lao People's Democratic Republic

LB

Lebanon

LR

Liberia

LI

Liechtenstein

LU

Luxembourg

MG

Madagascar

MY

Malaysia

ML

Mali

MH

Marshall Islands

MR

Mauritania

YT

Mayotte

FM

Micronesia, Federated States Of

MC

Monaco

MS

Montserrat

MZ

Mozambique

NA

Namibia

NP

Nepal

AN

Netherlands Antilles

NZ

New Zealand

NE

Niger

NU

Niue

MP

Northern Mariana Islands

OM

Oman

PW

Palau

PA

Panama

PY

Paraguay

PH

Philippines

PL

Poland

PR

Puerto Rico

GP

Guadeloupe

GT

Guatemala

GW

Guinea-Bissau

HT

Haiti

HN

Honduras

HU

Hungary

IN

India

IR

Iran (Islamic Republic Of)

IE

Ireland

IT

Italy

JP

Japan

KZ

Kazakhstan

KI

Kiribati

KR

Korea, Republic Of

KG

Kyrgyzstan

LV

Latvia

LS

Lesotho

LY

Libyan Arab Jamahiriya

LT

Lithuania

MK

Macedonia, The Former Yugoslav Republic Of

MW

Malawi

MV

Maldives

MT

Malta

MQ

Martinique

MU

Mauritius

MX

Mexico

MD

Moldova, Republic Of

MN

Mongolia

MA

Morocco

MM

Myanmar

NR

Nauru

NL

Netherlands

NC

New Caledonia

NI

Nicaragua

NG

Nigeria

NF

Norfolk Island

NO

Norway

PK

Pakistan

PS

Palestinian Territory, Occupied

PG

Papua New Guinea

PE

Peru

PN

Pitcairn

PT

Portugal

QA

Qatar

RE

Reunion

RU

Russian Federation

KN

Saint Kitts And Nevis

VC

Saint Vincent and The Grenadines

SM

San Marino

SA

Saudi Arabia

SC

Seychelles

SG

Singapore

SI

Slovenia

SO

Somalia

GS

South Georgia and The South Sandwich Islands

LK

Sri Lanka

PM

St. Pierre And Miquelon

SR

Suriname

SZ

Swaziland

CH

Switzerland

TW

Taiwan

TZ

Tanzania, United Republic Of

TG

Togo

TO

Tonga

TN

Tunisia

TM

Turkmenistan

TV

Tuvalu

UA

Ukraine

GB

United Kingdom

UM

United States Minor Outlying Islands

UZ

Uzbekistan

VA

Vatican City State (Holy See)

VN

Viet Nam

VI

Virgin Islands (U.S.)

EH

Western Sahara

YU

Yugoslavia

ZW

Zimbabwe

RO

Romania

RW

Rwanda

LC

Saint Lucia

WS

Samoa

ST

Sao Tome and Principe

SN

Senegal

SL

Sierra Leone

SK

Slovakia (Slovak Republic)

SB

Solomon Islands

ZA

South Africa

ES

Spain

SH

St. Helena

SD

Sudan

SJ

Svalbard And Jan Mayen Islands

SE

Sweden

SY

Syrian Arab Republic

TJ

Tajikistan

TH

Thailand

TK

Tokelau

TT

Trinidad and tobago

TR

Turkey

TC

Turks And Caicos Islands

UG

Uganda

AE

United Arab Emirates

US

United States

UY

Uruguay

VU

Vanuatu

VE

Venezuela

VG

Virgin Islands (British)

WF

Wallis and Futuna Islands

YE

Yemen

ZM

Zambia

Note  

Although the locale codes are not case sensitive, they are typically written in lowercase for the language and uppercase for the country.

I make extensive use of styles in the OOo documents that I write. I use a specific paragraph style to format my code samples. Each paragraph style allows you to set the default character attributes to use in the paragraph. In OOo, characters specify the locale so I set the locale for this paragraph style to unknown; this prevents the spell-checker from checking my code samples.

To tell OOo that a word is French, and should be checked as French, set the locale of the characters to French. The code in Listing 24 traverses the paragraphs in a document and sets the locale on each one.

Listing 24: Set a simple Writer document to use a French locale.
start example
 Sub SetDocumentLocale   Dim aLocale As New com.sun.star.lang.Locale   aLocale.Language = "fr"  'Set the Locale to use the French language   aLocale.Country = "FR"   'Set the Locale to use France as the country   Dim oCursor  'Cursor used to traverse the document.   Dim oText    'The document text object   oText = ThisComponent.Text         'Writer documents have a Text object   oCursor = oText.createTextCursor() 'Create a text cursor   REM Move cursor to the start of the document and do not select text.   oCursor.GoToStart(False)   REM Move to the end of the paragraph, selecting the entire paragraph.   REM gotoNextParagraph() returns False if it fails.   Do While oCursor.gotoNextParagraph(True)     oCursor.CharLocale = aLocale 'This can fail for some paragraph types     oCursor.goRight(0, False)    'Deselect all text   Loop End Sub 
end example
 

The spell-checker, hyphenation, and thesaurus all require a locale to function. They will not function, however, if they aren't properly configured. Use Tools Options Language Settings Writing Aids to configure these in OOo. The macro in Listing 25 obtains a SpellChecker, Hyphenator, and Thesaurus, all of which require a Locale object.

Listing 25: SpellCheckExample is found in the Generic module in this chapter's source code files as SC12.sxw.
start example
 Sub SpellCheckExample   Dim s()          'Contains the words to check   Dim vReturn      'Value returned from SpellChecker, Hyphenator, and Thesaurus   Dim i As Integer 'Utility index variable   Dim msg$         'Message string   REM Although I create an empty argument array, I could also   REM use Array() to return an empty array.   Dim emptyArgs() as new com.sun.star.beans.PropertyValue   Dim aLocale As New com.sun.star.lang.Locale   aLocale.Language = "en"  'Use the English language   aLocale.Country = "US"   'Use the United States as the country   REM Words to check for spelling, hyphenation, and thesaurus   s = Array("hello", "anesthesiologist",_       "PNEUMONOULTRAMICROSCOPICSILICOVOLCANOCONIOSIS",_       "Pitonyak", "misspell")   REM *********Spell Check Example!   Dim vSpeller As Variant   vSpeller = createUnoService("com.sun.star.linguistic2.SpellChecker")   'Use vReturn = vSpeller.spell(s, aLocale, emptyArgs()) if you want options!   For i = LBound(s()) To UBound(s())     vReturn = vSpeller.isValid(s(i), aLocale, emptyArgs())     msg = msg & vReturn & " for " & s(i) & CHR$(10)   Next   MsgBox msg, 0, "Spell Check Words"   msg = ""   '******Hyphenation Example!   Dim vHyphen As Variant   vHyphen = createUnoService("com.sun.star.linguistic2.Hyphenator")   For i = LBound(s()) To UBound(s())     'vReturn = vHyphen.hyphenate(s(i), aLocale, 0, emptyArgs())     vReturn = vHyphen.createPossibleHyphens(s(i), aLocale, emptyArgs())     If IsNull(vReturn) Then       'hyphenation is probablly off in the configuration       msg = msg & " null for " & s(i) & CHR$(10)     Else       msg = msg & vReturn.getPossibleHyphens() & " for " & s(i) & CHR$(10)     End If   Next   MsgBox msg, 0, "Hyphenate Words"   msg = ""   '******Thesaurus Example!   Dim vThesaurus As Variant   Dim j As Integer, k As Integer   vThesaurus = createUnoService("com.sun.star.linguistic2.Thesaurus")   s = Array("hello", "stamp", "cool")   For i = LBound(s()) To UBound(s())     vReturn = vThesaurus.queryMeanings(s(i), aLocale, emptyArgs())     If UBound(vReturn) < 0 Then       Print "Thesaurus found nothing for " & s(i)     Else       msg = "Word " & s(i) & " has the following meanings:" & CHR$(10)       For j = LBound(vReturn) To UBound(vReturn)         msg=msg & CHR$(10) & "Meaning = " & vReturn(j).getMeaning() & CHR$(10)         msg = msg & Join(vReturn(j).querySynonyms(), " ") & CHR$(10)       Next       MsgBox msg, 0, "Althernate Meanings"     End If   Next End Sub 
end example
 

It is possible to obtain the default locale that is configured for OOo. Laurent Godard, an active OpenOffice.org volunteer, wrote the macro in Listing 26 , which obtains OOo's currently configured locale.

Listing 26: OOoLang() is found in the Generic module in this chapter's source code files as SC12.sxw.
start example
 Sub OOoLang()   'Retreives the running ooo version   'Author : Laurent Godard   'e-mail : listes.godard@laposte.net   '   Dim aSettings, aConfigProvider   Dim aParams2(0) As new com.sun.star.beans.PropertyValue   Dim sProvider$, sAccess$   sProvider = "com.sun.star.configuration.ConfigurationProvider"   sAccess   = "com.sun.star.configuration.ConfigurationAccess"   aConfigProvider = createUnoService(sProvider)   aParams2(0).Name = "nodepath"   aParams2(0).Value = "/org.openoffice.Setup/LlON"   aSettings = aConfigProvider.createInstanceWithArguments(sAccess, aParams2())   Dim OOLangue as string   OOLangue= aSettings.getbyname("ooLocale")    'en-US   MsgBox "OOo is configured with Locale " & OOLangue, 0, "OOo Locale" End Sub 
end example
 



OpenOffice.org Macros Explained
OpenOffice.org Macros Explained
ISBN: 1930919514
EAN: 2147483647
Year: 2004
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net