1 'encoding UTF-8 Do not remove or change this line!
2 '**************************************************************************
3 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 '* Copyright 2008 by Sun Microsystems, Inc.
7 '* OpenOffice.org - a multi-platform office productivity suite
9 '* $RCSfile: i18n_tools.inc,v $
13 '* last change: $Author: jsi $ $Date: 2008-06-16 12:19:06 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/******************************************************************************
34 '* owner : joerg.skottke@sun.com
36 '* short description : Tools to ease working with language dependent strings/values
38 '\******************************************************************************
40 function hGetI18nData( cSection as string, cLanguage as string ) as string
42 '///<h3>Retrieve various information about i18n</h3>
43 '///<i>Uses datafile: framework/tools/input/i18ndata.txt</i><br>
46 '///+<li>Section from which to retrieve the data (string)</li>
48 '///+<li>Any name of a section existing in the datafile</li>
50 '///+<li>Language code as string</li>
52 '///+<li>Use hGetTwoDigitLangCode(...) to ensure proper string formatting</li>
57 '///+<li>Language identifier (string)</li>
59 '///<u>Description</u>:
62 '///+<li>Create the path to the datafile</li>
64 cPath = gTesttoolPath & "framework\tools\input\i18ndata.txt"
65 cPath = convertpath( cPath )
67 '///+<li>Find out the required size of the array to hold the entire file</li>
68 dim iFileSize as integer
69 iFileSize = hListFileGetSize( cPath )
71 '///+<li>Define an array to hold the datafile</li>
72 dim aFileContent( iFileSize ) as string
74 '///+<li>Retrieve the requested section from the datafile</li>
75 hGetDatafileSection( cPath, aFileContent(), cSection, "", "" )
77 '///+<li>Isolate the requested language item</li>
78 hGetI18nData() = hGetValueForKeyAsString( aFileContent(), cLanguage )
84 '*******************************************************************************
86 function hGetTwoDigitLangCode( iLanguage as integer ) as string
88 '///<h3>Retrieve a two digit language code from integer</h3>
89 '///<i>Replaces and enhances deprecated sub "siSpracheSetzen"</i><br>
92 '///+<li>Language Code (integer)</li>
94 '///+<li>Any number between (and including) 1 and 99</li>
99 '///+<li>Language Code (string)</li>
101 '///+<li>1 - 9 -> "01" - "09"</li>
102 '///+<li>10 - 99 -> "10" - "99"</li>
105 '///<u>Description</u>:
107 dim cLanguage as string
109 '///+<li>Convert single digit language code to two digit language string</li>
110 if ( ( iLanguage > 0 ) and ( iLanguage < 10 ) ) then
111 cLanguage = "0" & iLanguage
113 cLanguage = iLanguage
116 hGetTwoDigitLangCode() = cLanguage
122 '*******************************************************************************
124 function hTestLocale() as boolean
127 '///<h3>Test whether we are running on an utf8 locale (Linux only)</h3><br>
129 '///<u>Parameter(s):</u><br>
131 '///+<li>No input parameters</li>
135 '///<u>Returns:</u><br>
137 '///+<li>Errorcondition (boolean)</li>
139 '///+<li>TRUE: Yes, this is a UTF-8 locale</li>
140 '///+<li>FALSE: Anything else</li>
144 const CFN = "hTestLocale::"
145 dim brc as boolean 'a multi purpose boolean returnvalue
152 '///<u>Description:</u>
155 if ( gtSysName = "Linux" ) then
157 '///+<li>Retrieve LANG</li>
158 lang = environ( "LANG" )
160 if ( instr( lang , "UTF8" ) or instr( lang , "UTF-8" ) ) then
164 '///+<li>Retrieve LC_ALL (Note that this variable is mostly set but has no value assigned)</li>
165 lc_all = environ( "LC_ALL" )
166 lc_all = ucase( lc_all )
167 if ( instr( lc_all , "UTF8" ) or instr( lc_all , "UTF-8" ) ) then
170 if ( lc_all = "" ) then
171 printlog( CFN & "No value set for LC_ALL, assuming UTF-8" )
174 printlog( CFN & "LC_ALL is set but has no UTF-8 locale" )
180 irc = 2 ' this is Windows and Solaris - they always can handle weird content
185 printlog( CFN & "UTF-8 locale found" )
188 printlog( CFN & "Please verify that you are running on UTF-8 locale" )
189 hTestLocale() = FALSE