理解CentOS7.4/docker terminal 编码 locale中文支持

2024-03-30 08:48

本文主要是介绍理解CentOS7.4/docker terminal 编码 locale中文支持,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

  • 获取编码格式

    From How to get terminal’s Character Encoding, the terminal uses environment variables to determine which character set to use, therefore you can determine it by looking at those variables: echo $LANG

  • locale

    Locales are used in Linux to define which language and character set (encoding) user see in the terminal.

    Locale is defined in the following format:

    <LANGUAGE>_<TERRITORY>.<CODESET>[@<MODIFIERS>]

    ITEMsFORMAT
    LANGUAGEISO 639 language code
    TERRITORYISO 3166 country code
    CODESETCharacter set or encoding identifier, like ISO-8859-1 or UTF-8

    locale是一个综合性的概念,是根据计算机用户所使用的语言、所在国家或者地区、当地的文化传统所定义的一个软件运行时的语言环境。

    这个语言环境可以按照所涉及的不同领域划分成几大类:用户所使用的语言符号及其分类(LC_CTYPE),数字 (LC_NUMERIC),比较和排序习惯(LC_COLLATE),时间显示格式(LC_TIME),货币单位(LC_MONETARY),信息主要是提示信息,错误信息, 状态信息, 标题, 标签, 按钮和菜单等(LC_MESSAGES),姓名书写方式(LC_NAME),地址书写方式(LC_ADDRESS),电话号码书写方式 (LC_TELEPHONE),度量衡表达方式(LC_MEASUREMENT),默认纸张尺寸大小(LC_PAPER)和locale对自身包含信息的概述(LC_IDENTIFICATION)。

    这些locale定义文件放在/usr/share/i18n/locales目录下

  • locale issues

    There are two questions: how to check and change the current locale and language settings from the command line in Linux.

    • check current locale and language settings
      # current locale and language settings
      $ locale 
      # list all enabled locales
      $ locale -a
      # list available encoding
      $ locale -m
      # locale and language settings are defined in the LANG variable
      $ echo $LANG
      
    • change the current locale and language settings
      • add new locale

        Before a locale can be enabled on the system, it must be generated.

        If you didn’t find the desired language or encoding in the list of enabled locales(locale -a), you can search for them in the list of all supported locales and install whatever you need.

        # for centos
        $ localedef --list-archive # list the all supported(available for generation) locales
        $ localedef -- list-archive | grep zh_CN.UTF-8 # find the desired locale 这一句好像无效
        $ sudo localedef -c -i zh_CN(locale定义文件) -f UTF-8(字符集) zh_CN.UTF-8 # generate it 
        $ locale -a | grep zh_CN.utf8 # available
        
      • already have useable locale

        To set the required locale and language for the current sesion - it is just needed to redefine LANG variable.

        $ LANG=zh_CN.utf8 # =两边不能有空格
        

        此方法设置后,echo $LANG 虽然显示zh_CN.utf8,但实际运行过程中中文还是乱码,而且locale命令下LANG未改变。

        $ export 
        
    • Define locale and language permanently

      Set the required value of the LANG variable in a user’s bash profile and the needed locale and language settings will be automatically loaded upon the each session.

      Put export LANG=zh_CN.utf8 line to the ~./bashrc or ~/.profile files.

      then source ~/.profile

  • Dockerfile

    修改基础镜像中文locale支持

    RUN yum -y update \&& yum install kde-l10n-Chinese -y \&& yum reinstall glibc-common -y \&& localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 \&& echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf \&& source /etc/locale.conf
    ENV LC_ALL=zh_CN.UTF-8 \LANG=zh_CN.UTF-8
    
  • Reference

  1. Linux: Define Locale and Language Settings

  2. 关于locale的设定,为什么要设定locale

  3. CentOS7及Docker配置中文字符集问题

这篇关于理解CentOS7.4/docker terminal 编码 locale中文支持的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/861029

相关文章

SpringBoot结合Docker进行容器化处理指南

《SpringBoot结合Docker进行容器化处理指南》在当今快速发展的软件工程领域,SpringBoot和Docker已经成为现代Java开发者的必备工具,本文将深入讲解如何将一个SpringBo... 目录前言一、为什么选择 Spring Bootjavascript + docker1. 快速部署与

深入理解Go语言中二维切片的使用

《深入理解Go语言中二维切片的使用》本文深入讲解了Go语言中二维切片的概念与应用,用于表示矩阵、表格等二维数据结构,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧... 目录引言二维切片的基本概念定义创建二维切片二维切片的操作访问元素修改元素遍历二维切片二维切片的动态调整追加行动态

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

SpringBoot+Docker+Graylog 如何让错误自动报警

《SpringBoot+Docker+Graylog如何让错误自动报警》SpringBoot默认使用SLF4J与Logback,支持多日志级别和配置方式,可输出到控制台、文件及远程服务器,集成ELK... 目录01 Spring Boot 默认日志框架解析02 Spring Boot 日志级别详解03 Sp

从原理到实战深入理解Java 断言assert

《从原理到实战深入理解Java断言assert》本文深入解析Java断言机制,涵盖语法、工作原理、启用方式及与异常的区别,推荐用于开发阶段的条件检查与状态验证,并强调生产环境应使用参数验证工具类替代... 目录深入理解 Java 断言(assert):从原理到实战引言:为什么需要断言?一、断言基础1.1 语

java实现docker镜像上传到harbor仓库的方式

《java实现docker镜像上传到harbor仓库的方式》:本文主要介绍java实现docker镜像上传到harbor仓库的方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录1. 前 言2. 编写工具类2.1 引入依赖包2.2 使用当前服务器的docker环境推送镜像2.2

Redis出现中文乱码的问题及解决

《Redis出现中文乱码的问题及解决》:本文主要介绍Redis出现中文乱码的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 问题的产生2China编程. 问题的解决redihttp://www.chinasem.cns数据进制问题的解决中文乱码问题解决总结

k8s上运行的mysql、mariadb数据库的备份记录(支持x86和arm两种架构)

《k8s上运行的mysql、mariadb数据库的备份记录(支持x86和arm两种架构)》本文记录在K8s上运行的MySQL/MariaDB备份方案,通过工具容器执行mysqldump,结合定时任务实... 目录前言一、获取需要备份的数据库的信息二、备份步骤1.准备工作(X86)1.准备工作(arm)2.手

华为鸿蒙HarmonyOS 5.1官宣7月开启升级! 首批支持名单公布

《华为鸿蒙HarmonyOS5.1官宣7月开启升级!首批支持名单公布》在刚刚结束的华为Pura80系列及全场景新品发布会上,除了众多新品的发布,还有一个消息也点燃了所有鸿蒙用户的期待,那就是Ha... 在今日的华为 Pura 80 系列及全场景新品发布会上,华为宣布鸿蒙 HarmonyOS 5.1 将于 7

RedisTemplate默认序列化方式显示中文乱码的解决

《RedisTemplate默认序列化方式显示中文乱码的解决》本文主要介绍了SpringDataRedis默认使用JdkSerializationRedisSerializer导致数据乱码,文中通过示... 目录1. 问题原因2. 解决方案3. 配置类示例4. 配置说明5. 使用示例6. 验证存储结果7.