2 * nls.c : Helpers for NLS programs.
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
27 #include <sys/types.h>
33 #include <apr_errno.h>
36 #include "svn_error.h"
37 #include "svn_pools.h"
40 #include "svn_private_config.h"
45 svn_error_t *err = SVN_NO_ERROR;
48 if (getenv("SVN_LOCALE_DIR"))
50 bindtextdomain(PACKAGE_NAME, getenv("SVN_LOCALE_DIR"));
55 WCHAR ucs2_path[MAX_PATH];
57 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]));
79 svn_error_createf(APR_EINVAL, NULL,
80 _("Can't convert string to UCS-2: '%s'"),
86 err = svn_error_create(APR_EINVAL, NULL,
87 _("Can't get module file name"));
93 outbytes = outlength = 3 * (inwords + 1);
94 utf8_path = apr_palloc(pool, outlength);
96 outbytes = WideCharToMultiByte(CP_UTF8, 0, ucs2_path, inwords,
97 utf8_path, outbytes, NULL, NULL);
101 err = svn_error_wrap_apr(apr_get_os_error(),
102 _("Can't convert module path "
103 "to UTF-8 from UCS-2: '%s'"),
108 utf8_path[outlength - outbytes] = '\0';
109 internal_path = svn_dirent_internal_style(utf8_path, pool);
110 /* get base path name */
111 internal_path = svn_dirent_dirname(internal_path, pool);
112 internal_path = svn_dirent_join(internal_path,
113 SVN_LOCALE_RELATIVE_PATH,
115 bindtextdomain(PACKAGE_NAME, internal_path);
118 svn_pool_destroy(pool);
121 bindtextdomain(PACKAGE_NAME, SVN_LOCALE_DIR);
125 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
126 bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
127 #endif /* HAVE_BIND_TEXTDOMAIN_CODESET */
129 #endif /* ENABLE_NLS */