Thư viện ngôn ngữ trong python là gì?

>>> nhập ngôn ngữ >>> loc = ngôn ngữ. setlocale[ngôn ngữ. LC_ALL] # lấy ngôn ngữ hiện tại >>> ngôn ngữ. setlocale[ngôn ngữ. LC_ALL, "de"] # sử dụng ngôn ngữ Đức >>> ngôn ngữ. strcoll["f\344n", "foo"] # so sánh chuỗi chứa âm sắc >>> ngôn ngữ. setlocale[ngôn ngữ. LC_ALL, ""] # sử dụng ngôn ngữ ưa thích của người dùng >>> ngôn ngữ. setlocale[ngôn ngữ. LC_ALL, "C"] # sử dụng ngôn ngữ mặc định [C] >>> ngôn ngữ. setlocale[ngôn ngữ. LC_ALL, loc] # khôi phục ngôn ngữ đã lưu

Mô-đun ngôn ngữ mở quyền truy cập vào chức năng và cơ sở dữ liệu ngôn ngữ POSIX. Cơ chế bản địa POSIX cho phép lập trình viên giải quyết các vấn đề văn hóa nhất định trong một ứng dụng mà không yêu cầu lập trình viên biết tất cả các chi tiết cụ thể của từng quốc gia nơi phần mềm được thực thi

Mô-đun ngôn ngữ được triển khai trên mô-đun _locale, do đó sử dụng triển khai ngôn ngữ ANSI C nếu có

Hàm nl_langinfo chấp nhận một trong các khóa sau. Hầu hết các mô tả được lấy từ mô tả tương ứng trong thư viện GNU C

Một thẻ đã tồn tại với tên chi nhánh được cung cấp. Nhiều lệnh Git chấp nhận cả tên thẻ và tên nhánh, vì vậy việc tạo nhánh này có thể gây ra hành vi không mong muốn. Bạn có chắc chắn muốn tạo nhánh này không?

Mô tả dự án

Địa phương - mô-đun cho các dự án đa ngôn ngữ

Bắt đầu

điều kiện tiên quyết

Địa phương chỉ sử dụng thư viện chuẩn json. Bạn cần viết bản dịch ở định dạng json

{
  "languages": {
      "ru": "Р СѓСЃСЃРєРёР№", "eng": "English", "sp": "EspaГ±ol"
  },

  "messages": {
      "welcome": {
          "ru": "Добро пожаловать!",
          "eng": "Welcome!"
      },
      "goodbye": {
          "ru": "РџРѕРєР°",
          "eng": "Goodbye",
          "sp": "AdiГіs"
      }
  }
}

Cần có phím

$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
2 và
$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
3

Để tạo cùng một tệp, hãy sử dụng

import Locales

Locales[].example[]

cài đặt

Bạn có thể cài đặt Địa điểm bằng cách sử dụng pip

$ pip install locales

hoặc tải xuống

$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
4 và thả vào thư mục chứa dự án của bạn

sử dụng

import Locales

loc = Locales["filename.json"]
loc.set_default_lang["eng"]  # Set the language by default

print[loc.get["welcome"]]
# Welcome!

print[loc.get["welcome", "ru"]]
# Добро пожаловать!

print[loc.get_all["goodbye"]
# dict of key "goodbye"  ->  {'ru': 'РџРѕРєР°', 'eng': 'Goodbye', 'sp': 'AdiГіs'}

print[loc.get_by_name["English"]]
# returns the abbreviation[key] of the language  ->  eng

tác giả

Tập tin. ngôn ngữ-ví dụ-1. py nhập ngôn ngữ in "ngôn ngữ", "=>", ngôn ngữ. setlocale[ngôn ngữ. LC_ALL, ""] # giá trị định dạng số nguyên = 4711 ngôn ngữ in. định dạng["%d", giá trị, 1], "==", ngôn ngữ in. atoi[địa phương. định dạng["%d", giá trị, 1]] # giá trị dấu phẩy động = 47. 11 ngôn ngữ in. định dạng["%f", giá trị, 1], "==", ngôn ngữ in. atof[ngôn ngữ. định dạng["%f", giá trị, 1]] thông tin = ngôn ngữ. localeconv[] in thông tin["int_curr_symbol"]
$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
5
$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
6
$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
7
$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
8

Mô-đun

$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
7 là một phần của thư viện hỗ trợ quốc tế hóa và bản địa hóa của Python. Nó cung cấp một cách tiêu chuẩn để xử lý các hoạt động có thể phụ thuộc vào ngôn ngữ hoặc vị trí của người dùng. Ví dụ: nó xử lý định dạng số dưới dạng tiền tệ, so sánh các chuỗi để sắp xếp và làm việc với ngày tháng. Nó không bao gồm dịch thuật [xem mô-đun
$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
8] hoặc mã hóa Unicode [xem mô-đun
$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
9]

Ghi chú

Việc thay đổi ngôn ngữ có thể có sự phân nhánh trên toàn ứng dụng, vì vậy, phương pháp được khuyến nghị là tránh thay đổi giá trị trong thư viện và để ứng dụng đặt giá trị đó một lần. Trong các ví dụ trong phần này, ngôn ngữ được thay đổi nhiều lần trong một chương trình ngắn để làm nổi bật sự khác biệt trong cài đặt của các ngôn ngữ khác nhau. Nhiều khả năng một ứng dụng sẽ đặt ngôn ngữ một lần khi nó khởi động hoặc khi nhận được yêu cầu web và không thay đổi ngôn ngữ đó

Phần này đề cập đến một số chức năng cấp cao trong mô-đun

$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
7. Có những cái khác ở mức thấp hơn hoặc liên quan đến việc quản lý ngôn ngữ cho một ứng dụng [
$ LANG=en_US LC_CTYPE=en_US LC_ALL=en_US python3 locale_env.py

Environment settings:
  LC_ALL = en_US
  LC_CTYPE = en_US
  LANG = en_US
  LANGUAGE =

Locale from environment: ['en_US', 'ISO8859-1']

Numeric formatting:

  Decimal point      : "."
  Grouping positions : [3, 3, 0]
  Thousands separator: ","

Monetary formatting:

  International currency symbol   : "'USD '"
  Local currency symbol           : '$'
  Symbol precedes positive value  : 1
  Symbol precedes negative value  : 1
  Decimal point                   : "."
  Digits in fractional values     : 2
  Digits in fractional values,
                   international  : 2
  Grouping positions              : [3, 3, 0]
  Thousands separator             : ","
  Positive sign                   : ""
  Positive sign position          : Before value and symbol
  Negative sign                   : "-"
  Negative sign position          : Before value and symbol
1]

Thăm dò địa điểm hiện tại

Cách phổ biến nhất để cho phép người dùng thay đổi cài đặt ngôn ngữ cho ứng dụng là thông qua biến môi trường [

$ LANG=en_US LC_CTYPE=en_US LC_ALL=en_US python3 locale_env.py

Environment settings:
  LC_ALL = en_US
  LC_CTYPE = en_US
  LANG = en_US
  LANGUAGE =

Locale from environment: ['en_US', 'ISO8859-1']

Numeric formatting:

  Decimal point      : "."
  Grouping positions : [3, 3, 0]
  Thousands separator: ","

Monetary formatting:

  International currency symbol   : "'USD '"
  Local currency symbol           : '$'
  Symbol precedes positive value  : 1
  Symbol precedes negative value  : 1
  Decimal point                   : "."
  Digits in fractional values     : 2
  Digits in fractional values,
                   international  : 2
  Grouping positions              : [3, 3, 0]
  Thousands separator             : ","
  Positive sign                   : ""
  Positive sign position          : Before value and symbol
  Negative sign                   : "-"
  Negative sign position          : Before value and symbol
2,
$ LANG=en_US LC_CTYPE=en_US LC_ALL=en_US python3 locale_env.py

Environment settings:
  LC_ALL = en_US
  LC_CTYPE = en_US
  LANG = en_US
  LANGUAGE =

Locale from environment: ['en_US', 'ISO8859-1']

Numeric formatting:

  Decimal point      : "."
  Grouping positions : [3, 3, 0]
  Thousands separator: ","

Monetary formatting:

  International currency symbol   : "'USD '"
  Local currency symbol           : '$'
  Symbol precedes positive value  : 1
  Symbol precedes negative value  : 1
  Decimal point                   : "."
  Digits in fractional values     : 2
  Digits in fractional values,
                   international  : 2
  Grouping positions              : [3, 3, 0]
  Thousands separator             : ","
  Positive sign                   : ""
  Positive sign position          : Before value and symbol
  Negative sign                   : "-"
  Negative sign position          : Before value and symbol
3,
$ LANG=en_US LC_CTYPE=en_US LC_ALL=en_US python3 locale_env.py

Environment settings:
  LC_ALL = en_US
  LC_CTYPE = en_US
  LANG = en_US
  LANGUAGE =

Locale from environment: ['en_US', 'ISO8859-1']

Numeric formatting:

  Decimal point      : "."
  Grouping positions : [3, 3, 0]
  Thousands separator: ","

Monetary formatting:

  International currency symbol   : "'USD '"
  Local currency symbol           : '$'
  Symbol precedes positive value  : 1
  Symbol precedes negative value  : 1
  Decimal point                   : "."
  Digits in fractional values     : 2
  Digits in fractional values,
                   international  : 2
  Grouping positions              : [3, 3, 0]
  Thousands separator             : ","
  Positive sign                   : ""
  Positive sign position          : Before value and symbol
  Negative sign                   : "-"
  Negative sign position          : Before value and symbol
4 hoặc
$ LANG=en_US LC_CTYPE=en_US LC_ALL=en_US python3 locale_env.py

Environment settings:
  LC_ALL = en_US
  LC_CTYPE = en_US
  LANG = en_US
  LANGUAGE =

Locale from environment: ['en_US', 'ISO8859-1']

Numeric formatting:

  Decimal point      : "."
  Grouping positions : [3, 3, 0]
  Thousands separator: ","

Monetary formatting:

  International currency symbol   : "'USD '"
  Local currency symbol           : '$'
  Symbol precedes positive value  : 1
  Symbol precedes negative value  : 1
  Decimal point                   : "."
  Digits in fractional values     : 2
  Digits in fractional values,
                   international  : 2
  Grouping positions              : [3, 3, 0]
  Thousands separator             : ","
  Positive sign                   : ""
  Positive sign position          : Before value and symbol
  Negative sign                   : "-"
  Negative sign position          : Before value and symbol
5, tùy thuộc vào nền tảng]. Sau đó, ứng dụng gọi
$ LANG=en_US LC_CTYPE=en_US LC_ALL=en_US python3 locale_env.py

Environment settings:
  LC_ALL = en_US
  LC_CTYPE = en_US
  LANG = en_US
  LANGUAGE =

Locale from environment: ['en_US', 'ISO8859-1']

Numeric formatting:

  Decimal point      : "."
  Grouping positions : [3, 3, 0]
  Thousands separator: ","

Monetary formatting:

  International currency symbol   : "'USD '"
  Local currency symbol           : '$'
  Symbol precedes positive value  : 1
  Symbol precedes negative value  : 1
  Decimal point                   : "."
  Digits in fractional values     : 2
  Digits in fractional values,
                   international  : 2
  Grouping positions              : [3, 3, 0]
  Thousands separator             : ","
  Positive sign                   : ""
  Positive sign position          : Before value and symbol
  Negative sign                   : "-"
  Negative sign position          : Before value and symbol
6 mà không có giá trị mã hóa cứng và giá trị môi trường được sử dụng

import Locales

Locales[].example[]
4

Phương thức

$ LANG=en_US LC_CTYPE=en_US LC_ALL=en_US python3 locale_env.py

Environment settings:
  LC_ALL = en_US
  LC_CTYPE = en_US
  LANG = en_US
  LANGUAGE =

Locale from environment: ['en_US', 'ISO8859-1']

Numeric formatting:

  Decimal point      : "."
  Grouping positions : [3, 3, 0]
  Thousands separator: ","

Monetary formatting:

  International currency symbol   : "'USD '"
  Local currency symbol           : '$'
  Symbol precedes positive value  : 1
  Symbol precedes negative value  : 1
  Decimal point                   : "."
  Digits in fractional values     : 2
  Digits in fractional values,
                   international  : 2
  Grouping positions              : [3, 3, 0]
  Thousands separator             : ","
  Positive sign                   : ""
  Positive sign position          : Before value and symbol
  Negative sign                   : "-"
  Negative sign position          : Before value and symbol
7 trả về một từ điển chứa các quy ước của miền địa phương. Danh sách đầy đủ các tên và định nghĩa giá trị được trình bày trong tài liệu thư viện tiêu chuẩn

Máy Mac chạy OS X 10. 11. 6 với tất cả các biến không được đặt sẽ tạo ra kết quả này

$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified

Chạy cùng một tập lệnh với bộ biến

$ LANG=en_US LC_CTYPE=en_US LC_ALL=en_US python3 locale_env.py

Environment settings:
  LC_ALL = en_US
  LC_CTYPE = en_US
  LANG = en_US
  LANGUAGE =

Locale from environment: ['en_US', 'ISO8859-1']

Numeric formatting:

  Decimal point      : "."
  Grouping positions : [3, 3, 0]
  Thousands separator: ","

Monetary formatting:

  International currency symbol   : "'USD '"
  Local currency symbol           : '$'
  Symbol precedes positive value  : 1
  Symbol precedes negative value  : 1
  Decimal point                   : "."
  Digits in fractional values     : 2
  Digits in fractional values,
                   international  : 2
  Grouping positions              : [3, 3, 0]
  Thousands separator             : ","
  Positive sign                   : ""
  Positive sign position          : Before value and symbol
  Negative sign                   : "-"
  Negative sign position          : Before value and symbol
4 cho biết cách ngôn ngữ và mã hóa mặc định thay đổi

Hoa Kỳ [____89]

________số 8

Pháp [

$ pip install locales
00]

$ pip install locales
0

Tây Ban Nha [

$ pip install locales
01]

$ pip install locales
3

Bồ Đào Nha [

$ pip install locales
02]

$ pip install locales
5

Ba Lan [

$ pip install locales
03]

$ pip install locales
7

Tiền tệ

Đầu ra ví dụ trước đó cho thấy rằng việc thay đổi ngôn ngữ sẽ cập nhật cài đặt ký hiệu tiền tệ và ký tự để phân tách các số nguyên khỏi phân số thập phân. Ví dụ này lặp qua một số ngôn ngữ khác nhau để in giá trị tiền tệ dương và âm được định dạng cho từng ngôn ngữ

$ pip install locales
8

Đầu ra là cái bàn nhỏ này

$ pip install locales
9

định dạng số

Các số không liên quan đến tiền tệ cũng được định dạng khác nhau tùy thuộc vào ngôn ngữ. Cụ thể, ký tự

$ pip install locales
04 được sử dụng để phân tách các số lớn thành các phần có thể đọc được sẽ thay đổi

import Locales

loc = Locales["filename.json"]
loc.set_default_lang["eng"]  # Set the language by default

print[loc.get["welcome"]]
# Welcome!

print[loc.get["welcome", "ru"]]
# Добро пожаловать!

print[loc.get_all["goodbye"]
# dict of key "goodbye"  ->  {'ru': 'РџРѕРєР°', 'eng': 'Goodbye', 'sp': 'AdiГіs'}

print[loc.get_by_name["English"]]
# returns the abbreviation[key] of the language  ->  eng
1

Để định dạng số không có ký hiệu tiền tệ, hãy sử dụng

$ pip install locales
05 thay vì
$ pip install locales
06

$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
0

Để chuyển đổi các số được định dạng bằng ngôn ngữ thành định dạng bất khả tri theo ngôn ngữ được chuẩn hóa, hãy sử dụng

$ pip install locales
07

$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
1

Dấu chấm câu trong nhóm bị xóa và dấu phân cách thập phân được chuyển thành luôn là

$ pip install locales
08

$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
2

Phân tích số

Bên cạnh việc tạo đầu ra ở các định dạng khác nhau, mô-đun

$ LANG= LC_CTYPE= PYTHONCOERCECLOCALE=0 python3 locale_env.py

Environment settings:
  LC_ALL =
  LC_CTYPE =
  LANG =
  LANGUAGE =

Locale from environment: [None, None]

Numeric formatting:

  Decimal point      : "."
  Grouping positions : []
  Thousands separator: ""

Monetary formatting:

  International currency symbol   : "''"
  Local currency symbol           : ''
  Symbol precedes positive value  : 127
  Symbol precedes negative value  : 127
  Decimal point                   : ""
  Digits in fractional values     : 127
  Digits in fractional values,
                   international  : 127
  Grouping positions              : []
  Thousands separator             : ""
  Positive sign                   : ""
  Positive sign position          : Unspecified
  Negative sign                   : ""
  Negative sign position          : Unspecified
7 giúp phân tích cú pháp đầu vào. Nó bao gồm các hàm
$ pip install locales
30 và
$ pip install locales
31 để chuyển đổi các chuỗi thành các giá trị số nguyên và dấu phẩy động dựa trên các quy ước định dạng số của ngôn ngữ

Định dạng ngôn ngữ là gì?

Một ngôn ngữ bao gồm một số danh mục có định dạng phụ thuộc vào quốc gia hoặc các thông số kỹ thuật khác tồn tại . Ngôn ngữ của chương trình xác định bộ mã, quy ước định dạng ngày và giờ, quy ước tiền tệ, quy ước định dạng thập phân và thứ tự đối chiếu [sắp xếp].

Cài đặt ngôn ngữ là gì?

Cài đặt ngôn ngữ xác định ngôn ngữ của giao diện người dùng và định dạng hiển thị cho thông tin như thời gian, ngày tháng và tiền tệ . MATLAB® sử dụng ngôn ngữ do người dùng chỉ định trên tất cả các nền tảng. Nếu MATLAB không hiển thị chính xác các ký tự trong ngôn ngữ của bạn, bạn có thể gặp sự cố cài đặt ngôn ngữ.

Chủ Đề