<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dinoy Raj</title>
    <description>The latest articles on DEV Community by Dinoy Raj (@dinoyraj).</description>
    <link>https://dev.to/dinoyraj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1410661%2Fcd2cd87a-516c-4b6f-a901-b5f5fd75ccb0.jpeg</url>
      <title>DEV Community: Dinoy Raj</title>
      <link>https://dev.to/dinoyraj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dinoyraj"/>
    <language>en</language>
    <item>
      <title>List Formatter in Android : Android Internationalization part 1</title>
      <dc:creator>Dinoy Raj</dc:creator>
      <pubDate>Sun, 07 Apr 2024 17:42:36 +0000</pubDate>
      <link>https://dev.to/dinoyraj/list-formatter-in-android-android-internationalization-part-1-3pii</link>
      <guid>https://dev.to/dinoyraj/list-formatter-in-android-android-internationalization-part-1-3pii</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KrXDigBP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AlcF-e7WpY0mcU1V0bITDqQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KrXDigBP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AlcF-e7WpY0mcU1V0bITDqQ.png" alt="List formattter" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you are addressing a larger audience of distinct linguistic, and cultural behaviours it is essential that your application content evolve according to the preferences that the user locale demands. especially dealing with strings or human-readable text that is displayed in the user interface, the aspect of translating and formatting it to adapt the usage corresponding to the user default locale turns out to be vital as it ensures a smooth user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Need for list formatter
&lt;/h2&gt;

&lt;p&gt;While generating a message from an arbitrarily sized list of terms/strings/units we might have to reformat them as conjunctions or disjunctions. The choice and positioning of separators and connectors ( conjunction/ disjunction ) can differ depending on the locale&lt;/p&gt;

&lt;p&gt;for example, consider a list of string&lt;/p&gt;

&lt;p&gt;&lt;code&gt;val language = ["Kotlin", "Java", "XML"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;where you want to generate a message by the conjunction of all items in language list, like “Kotlin, Java, and XML used in Android development ”&lt;/p&gt;

&lt;p&gt;Looks pretty straightforward to join string using a separator (, ) and connect the penultimate one with a connector but actual structure and usage varies according to locale (refer table below)&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  ListFormatter Class
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;ListFormatter&lt;/em&gt; is an immutable java class inside &lt;em&gt;package android.icu.text&lt;/em&gt; used to format list of items with a separator and connectors appropriate for a given locale&lt;/p&gt;

&lt;p&gt;create an instance of list formatter using getInstance() method either by passing the required locale along with width and type for formatting. By default it format accoording to  default locale along with conjunction as type and wide as width&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getInstance(Localelocale,ListFormatter.Typetype,ListFormatter.Widthwidth)

val formatter = ListFormatter.getInstance(Locale.getDefault())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Overview about parameters
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Locale
&lt;/h3&gt;

&lt;p&gt;use Locale.getDefault() to get the default locale based on user device or custom locale depends upon your use case&lt;/p&gt;
&lt;h3&gt;
  
  
  Type
&lt;/h3&gt;

&lt;p&gt;specified according to the type of meaning expressed by the list, Type Enum inside ListFormatter class ( ListFormatter.Type )&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  Width
&lt;/h3&gt;

&lt;p&gt;controls the verbosity level of connectors, determines the size (width) of the string returned&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  To sum up
&lt;/h2&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Got any questions? Leave a comment below or connect me through Twitter.. :)

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>androiddev</category>
      <category>jetpackcompose</category>
    </item>
  </channel>
</rss>
