1 @node Internationalisation
2 @chapter Internationalisation
4 Internationalisation in pspp is complicated.
5 The most annoying aspect is that of character-encoding.
6 This chapter attempts to describe the problems and current ways
7 in which they are addressed.
10 @section The working locales
11 Pspp has three ``working'' locales:
14 @item The locale of the user interface.
15 @item The locale of the output.
16 @item The locale of the data. Only the character encoding is relevant.
19 Each of these locales may, at different times take
20 separate (or identical) values.
21 So for example, a French statistician can use pspp to prepare a report
22 in the English language, using
23 a datafile which has been created by a Japanese researcher hence
24 uses a Japanese character set.
26 It's rarely, if ever, necessary to interrogate the system to find out
27 the values of the 3 locales.
28 However it's important to be aware of the source (destination) locale
29 when reading (writing) string data.
30 When transfering data between a source and a destination, the appropriate
31 recoding must be performed.
34 @subsection The user interface locale
35 This is the locale which is visible to the person using pspp.
36 Error messages and confidence indications are written in this locale.
37 For example ``Cannot open file'' will be written in the user interface locale.
39 This locale is set from the environment of the user who starts pspp@{ire@} or
40 from the system locale if not set.
42 @subsection The output locale
43 This locale is the one that should be visible to the person reading a
44 report generated by pspp. Non-data related strings (Eg: ``Page number'',
45 ``Standard Deviation'' etc.) will appear in this locale.
47 @subsection The data locale
48 This locale is the one associated with the data being analysed with pspp.
49 The only important aspect of this locale is the character encoding.
50 @footnote {It might also be desirable for the LC_COLLATE category to be used for the purposes of sorting data.}
51 The dictionary pertaining to the data contains a field denoting the encoding.
52 Any string data stored in a @union{value} will be encoded in the
53 dictionary's character set.
57 @file{*.sav} files contain a field which is supposed to identify the encoding
58 of the data they contain (@pxref{Machine Integer Info Record}).
60 files produced by early versions of spss set this to ``2'' (ASCII) regardless
61 of the encoding of the data.
62 Later versions contain an additional
63 record (@pxref{Character Encoding Record}) describing the encoding.
64 When a system file is read, the dictionary's encoding is set using information
65 gleened from the system file.
66 If the encoding cannot be determined or would be unreliable, then it
71 The psppire graphic user interface is written using the Gtk+ api, for which
72 all strings must be encoded in UTF8.
73 All strings passed to the GTK+/GLib library functions (except for filenames)
74 must be UTF-8 encoded otherwise errors will occur.
75 Thus, for the purposes of the programming psppire, the user interface locale
76 should be assumed to be UTF8, even if setlocale and/or nl_langinfo
80 The GLib API has some special functions for dealing with filenames.
81 Strings returned from functions like gtk_file_chooser_dialog_get_name are not,
82 in general, encoded in UTF8, but in ``filename'' encoding.
83 If that filename is passed to another GLib function which expects a filename,
84 no conversion is necessary.
85 If it's passed to a function for the purposes of displaying it (eg. in a
86 window's title-bar) it must be converted to UTF8 --- there is a special
87 function for this: g_filename_display_name or g_filename_basename.
88 If however, a filename needs to be passed outside of GTK+/GLib (for example to fopen) it must be converted to the local system encoding.
91 @section Existing locale handling functions
92 The major aspect of locale handling which the programmer has to consider is
93 that of character encoding.
95 The following function is used to recode strings:
97 @deftypefun char * recode_string (const char *@var{to}, const char *@var{from}, const char *@var{text}, int @var{len});
99 Converts the string @var{text}, which is encoded in @var{from} to a new string encoded in @var{to} encoding.
100 If @var{len} is not -1, then it must be the number of bytes in @var{text}.
101 It is the caller's responsibility to free the returned string when no
105 In order to minimise the number of conversions required, and to simplify
106 design, PSPP attempts to store all internal strings in UTF8 encoding.
107 Thus, when reading system and portable files (or any other data source),
108 the following items are immediately converted to UTF8 encoding:
111 @item Variable labels
114 Conversely, when writing system files, these are converted back to the
115 encoding of that system file.
117 String data stored in union values are left in their original encoding.
118 These will be converted by the data_in/data_out functions.
123 For historical reasons, not all locale handling follows posix conventions.
124 This makes it difficult (impossible?) to elegantly handle the issues.
125 For example, it would make sense for the gui's datasheet to display
126 numbers formatted according to the LC_NUMERIC category of the data locale.
127 Instead however there is the @func{data_out} function
128 (@pxref{Obtaining Properties of Format Types}) which uses the
129 @func{settings_get_decimal_char} function instead of the decimal separator
130 of the locale. Similarly, formatting of monetary values is displayed
131 in a pspp/spss specific fashion instead of using the LC_MONETARY category.
135 @c LocalWords: pspp itemize Eg LC Spss cmd sav pxref spss GUI psppire Gtk api
136 @c LocalWords: UTF gtk setlocale nl langinfo deftypefun enum conv var const
137 @c LocalWords: int len gui struct val utf GtkWidget posix gui's datasheet