Change the format of the revprops block sent in svnserve for
[svn.git] / subversion / libsvn_subr / nls.c
blob07a348f00f956d36586e2c5afd8bce082809a823
1 /*
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 * ====================================================================
19 #include <stdlib.h>
21 #ifndef WIN32
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26 #endif
28 #include <apr_errno.h>
30 #include "svn_nls.h"
31 #include "svn_error.h"
32 #include "svn_pools.h"
33 #include "svn_path.h"
35 #include "svn_private_config.h"
37 #ifdef WIN32
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>
43 #endif
46 svn_error_t *
47 svn_nls_init(void)
49 svn_error_t *err = SVN_NO_ERROR;
51 #ifdef ENABLE_NLS
52 #ifdef WIN32
54 WCHAR ucs2_path[MAX_PATH];
55 char* utf8_path;
56 const char* internal_path;
57 apr_pool_t* pool;
58 apr_status_t apr_err;
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]));
65 if (! inwords)
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)))
73 inwords =
74 MultiByteToWideChar(CP_ACP, 0, ansi_path, -1, ucs2_path,
75 sizeof(ucs2_path) / sizeof(ucs2_path[0]));
76 if (! inwords) {
77 err =
78 svn_error_createf(APR_EINVAL, NULL,
79 _("Can't convert string to UCS-2: '%s'"),
80 ansi_path);
83 else
85 err = svn_error_create(APR_EINVAL, NULL,
86 _("Can't get module file name"));
90 if (! err)
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;
98 if (apr_err)
100 err = svn_error_createf(apr_err, NULL,
101 _("Can't convert module path "
102 "to UTF-8 from UCS-2: '%s'"),
103 ucs2_path);
105 else
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,
113 pool);
114 bindtextdomain(PACKAGE_NAME, internal_path);
117 svn_pool_destroy(pool);
119 #else
120 bindtextdomain(PACKAGE_NAME, SVN_LOCALE_DIR);
121 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
122 bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
123 #endif
124 #endif
125 #endif
127 return err;