Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "pal_icushim_internal.h"
#include "pal_icushim.h"
Expand All @@ -11,6 +12,13 @@
#include <unicode/localpointer.h>
#include <unicode/utrace.h>

#if defined(TARGET_UNIX)
#include <strings.h>
#elif defined(TARGET_WINDOWS)
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif

static int32_t isLoaded = 0;
static int32_t isDataSet = 0;

Expand All @@ -30,6 +38,37 @@ static void U_CALLCONV icu_trace_data(const void* context, int32_t fnNumber, int
#ifdef __EMSCRIPTEN__
#include <emscripten.h>

EMSCRIPTEN_KEEPALIVE const char* mono_wasm_get_icudt_name(const char* culture);

EMSCRIPTEN_KEEPALIVE const char* mono_wasm_get_icudt_name(const char* culture)
{
// Based on https://github.com/dotnet/icu/tree/maint/maint-67/icu-filters

// Use full one if culture is null or empty
if (!culture || strlen(culture) < 2)
return "icudt.dat";

// CJK: starts with "ja", "ko" or "zh"
if (!strncasecmp("ja", culture, 2) ||
!strncasecmp("ko", culture, 2) ||
!strncasecmp("zh", culture, 2))
return "icudt_CJK.dat"; // contains "en" as well.

// EFIGS
const char* efigsCultures[15] = {
"en-US", "fr-FR", "es-ES", "it-IT", "de-DE",
"en_US", "fr_FR", "es_ES", "it_IT", "de_DE",
"en", "fr", "es", "it", "de"
};

for (int i = 0; i < 15; i++)
if (!strcasecmp(culture, efigsCultures[i]))
return "icudt_EFIGS.dat";

// full except CJK cultures
return "icudt_no_CJK.dat";
}

EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data(void * pData);

EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data(void * pData)
Expand Down
9 changes: 9 additions & 0 deletions src/mono/wasm/runtime/library_mono.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var MonoSupportLib = {
module ["mono_load_runtime_and_bcl_args"] = MONO.mono_load_runtime_and_bcl_args;
module ["mono_wasm_load_bytes_into_heap"] = MONO.mono_wasm_load_bytes_into_heap;
module ["mono_wasm_load_icu_data"] = MONO.mono_wasm_load_icu_data;
module ["mono_wasm_get_icudt_name"] = MONO.mono_wasm_get_icudt_name;
module ["mono_wasm_globalization_init"] = MONO.mono_wasm_globalization_init;
module ["mono_wasm_get_loaded_files"] = MONO.mono_wasm_get_loaded_files;
module ["mono_wasm_new_root_buffer"] = MONO.mono_wasm_new_root_buffer;
Expand Down Expand Up @@ -1379,6 +1380,14 @@ var MonoSupportLib = {
return ok;
},

// Get icudt.dat exact filename that matches given culture, examples:
// "ja" -> "icudt_CJK.dat"
// "en_US" (or "en-US" or just "en") -> "icudt_EFIGS.dat"
// etc, see "mono_wasm_get_icudt_name" implementation in pal_icushim_static.c
mono_wasm_get_icudt_name: function (culture) {
return Module.ccall ('mono_wasm_get_icudt_name', 'string', ['string'], [culture]);
},

_finalize_startup: function (args, ctx) {
var loaded_files_with_debug_info = [];

Expand Down