summaryrefslogtreecommitdiff
path: root/src/node_i18n.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_i18n.cc')
-rw-r--r--src/node_i18n.cc88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/node_i18n.cc b/src/node_i18n.cc
new file mode 100644
index 0000000000..6d6144dc78
--- /dev/null
+++ b/src/node_i18n.cc
@@ -0,0 +1,88 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+/*
+ * notes: by srl295
+ * - When in NODE_HAVE_SMALL_ICU mode, ICU is linked against "stub" (null) data
+ * ( stubdata/libicudata.a ) containing nothing, no data, and it's also
+ * linked against a "small" data file which the SMALL_ICUDATA_ENTRY_POINT
+ * macro names. That's the "english+root" data.
+ *
+ * If icu_data_path is non-null, the user has provided a path and we assume
+ * it goes somewhere useful. We set that path in ICU, and exit.
+ * If icu_data_path is null, they haven't set a path and we want the
+ * "english+root" data. We call
+ * udata_setCommonData(SMALL_ICUDATA_ENTRY_POINT,...)
+ * to load up the english+root data.
+ *
+ * - when NOT in NODE_HAVE_SMALL_ICU mode, ICU is linked directly with its full
+ * data. All of the variables and command line options for changing data at
+ * runtime are disabled, as they wouldn't fully override the internal data.
+ * See: http://bugs.icu-project.org/trac/ticket/10924
+ */
+
+
+#include "node_i18n.h"
+
+#if defined(NODE_HAVE_I18N_SUPPORT)
+
+#include <unicode/putil.h>
+#include <unicode/udata.h>
+
+#ifdef NODE_HAVE_SMALL_ICU
+/* if this is defined, we have a 'secondary' entry point.
+ compare following to utypes.h defs for U_ICUDATA_ENTRY_POINT */
+#define SMALL_ICUDATA_ENTRY_POINT \
+ SMALL_DEF2(U_ICU_VERSION_MAJOR_NUM, U_LIB_SUFFIX_C_NAME)
+#define SMALL_DEF2(major, suff) SMALL_DEF(major, suff)
+#ifndef U_LIB_SUFFIX_C_NAME
+#define SMALL_DEF(major, suff) icusmdt##major##_dat
+#else
+#define SMALL_DEF(major, suff) icusmdt##suff##major##_dat
+#endif
+
+extern "C" const char U_DATA_API SMALL_ICUDATA_ENTRY_POINT[];
+#endif
+
+namespace node {
+namespace i18n {
+
+bool InitializeICUDirectory(const char* icu_data_path) {
+ if (icu_data_path != NULL) {
+ u_setDataDirectory(icu_data_path);
+ return true; // no error
+ } else {
+ UErrorCode status = U_ZERO_ERROR;
+#ifdef NODE_HAVE_SMALL_ICU
+ // install the 'small' data.
+ udata_setCommonData(&SMALL_ICUDATA_ENTRY_POINT, &status);
+#else // !NODE_HAVE_SMALL_ICU
+ // no small data, so nothing to do.
+#endif // !NODE_HAVE_SMALL_ICU
+ return (status == U_ZERO_ERROR);
+ }
+}
+
+} // namespace i18n
+} // namespace node
+
+#endif // NODE_HAVE_I18N_SUPPORT