Servler commonly uses three internationalization implementations---currency/date/text

■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■↓↓↓↓↓↓↓↓ ↓ Software Internationalization↓↓↓↓↓↓↓↓↓↓↓■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ ■■■■■■■■■■■■■■■■■■■■■■■■


software internationalization;
   Why have it?
    When an application is released,
    Experienced by users in other regions,
    And this web application is not the current language and interface,
    Then the user experience is very poor.
   
   
   what is it?
     is to make this software can be used by people in different regions
     
     
   effect;
    ◆ Improve user experience
       Make the software more flexible and variable
    ◆ You can display a piece of data that can be directly displayed on the page, according to the local format

------------------------------- ----↓↓↓↓↓↓↓Software Internationalization——Common Attribute Internationalization↓↓↓↓↓↓↓↓----------------------- -------------------------


Commonly used attribute internationalization;
 1. Text internationalization
  ---> Because the texts of countries in different regions are different, making the user experience better
 
 2. Date internationalization
  ---> The date display format of each region may be different
 
 3. Currency internationalization
  ---> The currency identifiers in each region are different


--------------------------------↓↓ ↓↓↓↓↓Software Internationalization——Text Internationalization Label and Implementation↓↓↓↓↓↓↓------------------------- ---------------------


text internationalization;
   principle;
    They are all stored in a resource package, and the local language corresponds to the language of a certain country.
    The form of a key-value pair translates the corresponding key or value by looking up the resource bundle.
    And this file generally exists in the form of properties (similarly) in Java
     
   
   main class;
          ResourceBundle ---> used to bind resource bundles of different countries
        
          
 resource file naming rules;
    message-language-country (uppercase).properties
    
    
         code;   
     1.ResourceBundle resource = ResourceBundle.getBundle("package name/subpackage name/file", Locale.XX);

   Description; ResourceBundle is an abstract class,
    So it can only be obtained through static methods.
   
      Parameter 1; it is the incoming resource package, which is usually placed in a file or under a package.
      If the resource package is not found, it will find the default package message.properties by default
      If the default package is not found, it will use the system default language for translation

       
       ◆Note; the file name of this resource package does not need a suffix (.properties)
       Note; the naming convention will report an error
               
      Parameter two; Locale is the designated national language to be translated,
      And the static properties of this Locale have the abbreviations of various countries.
     
  If Locale.getDefault() is set then it will be used
  System default language for translation
  
  1.1resource.getString("xx"); ---> Get the value corresponding to the resource package  
  2.resource.getBundle(resource bundle, Locale); ---> This method can also bind resource packs
  
  
  
 
    Label;    
  use fmt internationalization tags;
      1. Import the tag library ["http://java.sun.com/jsp/jstl/fmt"] 
        2. <ftm:setBundle basename="Resource bundle (package name/file)"></fmt:setBundle>
    ---> Bind resource pack
        3. <ftm:message key="translated value"></ftm:message>
   
   ◆◆Note; you can put the <ftm:message> tag in a value attribute or name attribute
   
----------------------------------↓↓↓↓↓↓↓Software Internationalization—— Date Internationalization Label And realize ↓↓↓↓↓↓↓----------------------------------------- -------


date internationalization;
   Main class; DateFormat ---> date formatting class, which is an abstract class
   
    code;
         1.DataFormat df = DataFormat.getDataTimeInstance (DataFormat.Full, DataFormat.Full, Locale.getDefault ());
       
        illustrate;
            Parameter 1; is to set whether the date is displayed in detail, there are four levels
            short Mediumn long full
           
        Parameter 2; is to set whether the time is displayed in detail, there are four levels
short Mediumn long full
    
    Parameter 3; if the time format of the region (country) is set,
    getDefault() is to use the current system format by default
   
      2.df.format(new Date());    
   
   illustrate;
     Pass in a time, formatted according to the formal parameters of this object
      
       Label;
        1. Import the tag library ["http://java.sun.com/jsp/jstl/fmt"] 
       
        2.<fmt: formatDate value="${ applicationScope.date}" dateStyle="4"
        timeStyle="4" type="3"></fmt:formatDate>  
 
  Description; call the <fmt:formatDate> tag,
   value is a time passed in, usually a domain attribute is passed in  
 dateStyle sets whether the date is displayed in detail. There are 4 levels,
        --->  short - medium - long - full
 
 timeStyle sets whether the time is displayed in detail and has 4 levels
---> short - medium - long - full
  
  type sets the display format of the time, there are three
  - date display date 
  - time display time
  - both display time and date
 
--------------------------------↓↓↓↓↓↓↓Software Internationalization - Currency/Number Internationalization Label And realize ↓↓↓↓↓↓↓----------------------------------------- -------


currency/digital internationalization;
Main class; DecimalFormat

  code;
  1.DecimalFormat df = new DecimalFormat("\u2030 * \u00A4 * % * ##.#");
 
     illustrate;
      \u2030 is to perform thousandths calculation
      \u00A4 is to display the local currency symbol
      % is calculated as a percentage
      #.# is to round up if you want to keep a few decimal places
       
  2.df.format(number);
     
     illustrate;
          Pass in a number to format
 
          
Label;
1. Import the tag library ["http://java.sun.com/jsp/jstl/fmt"] 

2. <fmt:formatNumber value="number" pattern="#.#"></fmt:formatNumber>
   
    illustrate;
        value is the value to format
        pattern The format for formatting a number, #.# is to retain several decimal places
  
   <fmt:formatNumber value="number"  type="常用三种"></fmt:formatNumber>
   
    illustrate;
        value is the value to format
        type is what format to format
        
           Three are commonly used;
                number raw numeric output
                Precent is output in numerical form as a percentage          
          currency is formatted according to the local currency symbol
          
          
          
          

        
          
          
           

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326711357&siteId=291194637