2 * nls.c : Helpers for NLS programs.
4 * ====================================================================
5 * Copyright (c) 2000-2005 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
22 #include <sys/types.h>
28 #include <apr_errno.h>
31 #include "svn_error.h"
32 #include "svn_pools.h"
35 #include "svn_private_config.h"
38 /* FIXME: We're using an internal APR header here, which means we
39 have to build Subversion with APR sources. This being Win32-only,
40 that should be fine for now, but a better solution must be found in
41 combination with issue #850. */
42 #include <arch/win32/apr_arch_utf8.h>
49 svn_error_t
*err
= SVN_NO_ERROR
;
54 WCHAR ucs2_path
[MAX_PATH
];
56 const char* internal_path
;
59 apr_size_t inwords
, outbytes
, outlength
;
61 apr_pool_create(&pool
, 0);
62 /* get exe name - our locale info will be in '../share/locale' */
63 inwords
= GetModuleFileNameW(0, ucs2_path
,
64 sizeof(ucs2_path
) / sizeof(ucs2_path
[0]));
67 /* We must be on a Win9x machine, so attempt to get an ANSI path,
68 and convert it to Unicode. */
69 CHAR ansi_path
[MAX_PATH
];
71 if (GetModuleFileNameA(0, ansi_path
, sizeof(ansi_path
)))
74 MultiByteToWideChar(CP_ACP
, 0, ansi_path
, -1, ucs2_path
,
75 sizeof(ucs2_path
) / sizeof(ucs2_path
[0]));
78 svn_error_createf(APR_EINVAL
, NULL
,
79 _("Can't convert string to UCS-2: '%s'"),
85 err
= svn_error_create(APR_EINVAL
, NULL
,
86 _("Can't get module file name"));
92 outbytes
= outlength
= 3 * (inwords
+ 1);
93 utf8_path
= apr_palloc(pool
, outlength
);
94 apr_err
= apr_conv_ucs2_to_utf8(ucs2_path
, &inwords
,
95 utf8_path
, &outbytes
);
96 if (!apr_err
&& (inwords
> 0 || outbytes
== 0))
97 apr_err
= APR_INCOMPLETE
;
100 err
= svn_error_createf(apr_err
, NULL
,
101 _("Can't convert module path "
102 "to UTF-8 from UCS-2: '%s'"),
107 utf8_path
[outlength
- outbytes
] = '\0';
108 internal_path
= svn_path_internal_style(utf8_path
, pool
);
109 /* get base path name */
110 internal_path
= svn_path_dirname(internal_path
, pool
);
111 internal_path
= svn_path_join(internal_path
,
112 SVN_LOCALE_RELATIVE_PATH
,
114 bindtextdomain(PACKAGE_NAME
, internal_path
);
117 svn_pool_destroy(pool
);
120 bindtextdomain(PACKAGE_NAME
, SVN_LOCALE_DIR
);
121 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
122 bind_textdomain_codeset(PACKAGE_NAME
, "UTF-8");