]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/subversion/subversion/libsvn_subr/nls.c
MFC r275385 (by bapt):
[FreeBSD/stable/10.git] / contrib / subversion / subversion / libsvn_subr / nls.c
1 /*
2  * nls.c :  Helpers for NLS programs.
3  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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
20  *    under the License.
21  * ====================================================================
22  */
23
24 #include <stdlib.h>
25
26 #ifndef WIN32
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <unistd.h>
31 #endif
32
33 #include <apr_errno.h>
34
35 #include "svn_nls.h"
36 #include "svn_error.h"
37 #include "svn_pools.h"
38 #include "svn_path.h"
39
40 #include "private/svn_utf_private.h"
41
42 #include "svn_private_config.h"
43
44 svn_error_t *
45 svn_nls_init(void)
46 {
47   svn_error_t *err = SVN_NO_ERROR;
48
49 #ifdef ENABLE_NLS
50   if (getenv("SVN_LOCALE_DIR"))
51     {
52       bindtextdomain(PACKAGE_NAME, getenv("SVN_LOCALE_DIR"));
53     }
54   else
55     {
56 #ifdef WIN32
57       WCHAR ucs2_path[MAX_PATH];
58       const char* utf8_path;
59       const char* internal_path;
60       apr_pool_t* scratch_pool;
61
62       scratch_pool = svn_pool_create(NULL);
63       /* get exe name - our locale info will be in '../share/locale' */
64       GetModuleFileNameW(NULL, ucs2_path,
65           sizeof(ucs2_path) / sizeof(ucs2_path[0]));
66       if (apr_get_os_error())
67         {
68           err = svn_error_wrap_apr(apr_get_os_error(),
69                                    _("Can't get module file name"));
70         }
71
72       if (! err)
73         err = svn_utf__win32_utf16_to_utf8(&utf8_path, ucs2_path,
74                                            NULL, scratch_pool);
75
76       if (! err)
77         {
78           internal_path = svn_dirent_internal_style(utf8_path, scratch_pool);
79           /* get base path name */
80           internal_path = svn_dirent_dirname(internal_path, scratch_pool);
81           internal_path = svn_dirent_join(internal_path,
82                                           SVN_LOCALE_RELATIVE_PATH,
83                                           scratch_pool);
84           SVN_ERR(svn_dirent_get_absolute(&internal_path, internal_path,
85                                           scratch_pool));
86           bindtextdomain(PACKAGE_NAME, internal_path);
87         }
88
89       svn_pool_destroy(scratch_pool);
90     }
91 #else /* ! WIN32 */
92       bindtextdomain(PACKAGE_NAME, SVN_LOCALE_DIR);
93     }
94 #endif /* WIN32 */
95
96 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
97   bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
98 #endif /* HAVE_BIND_TEXTDOMAIN_CODESET */
99
100 #endif /* ENABLE_NLS */
101
102   return err;
103 }