File: test_browser_language_detection.c

package info (click to toggle)
emscripten 3.1.6~dfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 114,112 kB
  • sloc: ansic: 583,052; cpp: 391,943; javascript: 79,361; python: 54,180; sh: 49,997; pascal: 4,658; makefile: 3,426; asm: 2,191; lisp: 1,869; ruby: 488; cs: 142
file content (27 lines) | stat: -rw-r--r-- 731 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main(int argc, char** argv) {
  if (getenv("LANG")) {
    printf("%s\n", getenv("LANG"));
  }

#ifndef __EMSCRIPTEN__
  // Emscripten has no locale support in *scanf as of 2019-06.
  // These tests for future use - or native/desktop testing:
  char* cur_locale = setlocale(LC_ALL, "");
  printf("locale: %s\n", cur_locale);
  float ret = 0;
  sscanf("1,2", "%f", &ret);
  printf("%f\n", ret);
  sscanf("3.4", "%f", &ret);
  printf("%f\n", ret);
  
  // Expected results:
  // LANG=C ./a.out: 1 / 3.4
  // LANG=fr_FR.UTF-8 ./a.out: 1,2 / 3
  // Note: requested locale needs to be installed locally (cf. `locale -a`)
  //       otherwise setlocale(3) is no-op
#endif
}