Rectangle 27 1

According to the docs, LANGUAGE_CODE is set to the installation language code. Are you sure you've changed it from en-us in your settings file?

Have you tried printing the language code out at the end of your settings file and then running in a non-deamon mode so you can see it's output? Personally, I use multi-part configuration files and have previously had issues where latter settings files have altered something I expected to work further down the line. Is that a possibility?

If it looks right at the end of the settings file then it's probably not being fed through to the template properly. You could try pushing it through yourself like this to be sure.

One other thing to check; are you sure it's not settings.LANGUAGE_CODE you need? I can't remember whether that's just in the model off the top of my head.

I tried with and without LANGUAGE_CODE, with runserver, with Apache, daemon and non daemon...

What did printing out the value at the end of the settings give you?

but thanks for the mutli settings file idea, I thought they were clean but discovered some horrors there just right now and the locale middleware was not imported! i18n now works :) I'm going to clean that right away.

internationalization - How to debug Django i18n? - Stack Overflow

django internationalization
Rectangle 27 148

log_in_message_html: "This is a text, with a %{href} inside."
log_in_href: "link"

<p> <%= t("log_in_message_html", :href => link_to(t("log_in_href"), login_path)) %> </p>

In Rails 3 the syntax for this has changed to %{href} in the YAML translation string. Also, because output is automatically escaped, you need to either specify raw or .html_safe explicitly, or suffix your translation key with _html, as in login_message_html and escaping will be skipped automatically.

just in case if it isn't obvious (and for those too lazy to check the edit log).. the answer above was already edited to include @coreyward's comment.

If you have anything more than a single word in the link text splitting translations like this will yield weird translations. For example "We have an amazing <a href='x'>offering of assorted things</a> that you can buy. You send the chopped up thing to a translator and you are likely to get two phrased that read like "We have an amazing <a href='x'> whole bunch of items</a> that you can buy" in other languages. Best to find a solution that doesn't split them apart.

@Archonic That's not true. t('string') is identical to t("string"). They're the same thing.

@Archonic That's unrelated. We're talking about %{}, not #{}. Single or double quotes don't impact Rails' ability to interpolate variables into your locale files via %{}.

internationalization - rails i18n - translating text with links inside...

ruby-on-rails internationalization
Rectangle 27 51

You got to call a private method on the backend. This is how you get access:

translations = I18n.backend.send(:translations)
translations[:en][:test_string] # => "testing this"

Note that translations will be empty if the backend isn't initialized, i.e. if you haven't used it for anything else yet. You will see this if you open up a new console and try to load the translations. You can get around it by doing I18n.t(:foo); translations = I18n.backend.send(:translations) (even if you don't have a foo translation). I'm sure there's a better way.

I18n.backend.send(:init_translations) unless I18n.backend.initialized?

You do not need to use private methods. Just call I18n.t('.')

As an addition to @HenrikN comment, I'd say it can be initialized by calling I18n.enforce_available_locales!(:fr) where :fr is desirable locale.

internationalization - How to retrieve all translations from yml files...

ruby-on-rails internationalization yaml rails-i18n
Rectangle 27 41

In Rails 3.1 that is a little bit changed.

<% form_for @post do |f| %>
  <%= f.label :title %>
  <%= f.text_field :title %>
  <%= f.submit %>
<% end %>

en:
  helpers:
    label:
      post:
        title: 'Customized title'

Thanks for this. Is there a release note or something that I can look at to learn more about this format?

The description for this format is available in the ActionView::Helpers::FormHelper.label documentation.

I can confirm that this works for me in Rails 4.0 as well.

If the helpers: path is not available, i18n will fallback to the activerecord: path. Very clear when using the excellent i18n-debug gem.

internationalization - Rails i18n and yml structure for form labels - ...

ruby-on-rails internationalization yaml
Rectangle 27 11

Separating text and link in locale.yml file works for a while but with longer text those are hard to translate and maintain as the link is in separate translation-item (as in Simones answer). If you start having many strings/translations with links you can dry it a bit more.

# Converts
# "string with __link__ in the middle." to
# "string with #{link_to('link', link_url, link_options)} in the middle."
def string_with_link(str, link_url, link_options = {})
  match = str.match(/__([^_]{2,30})__/)
  if !match.blank?
    raw($` + link_to($1, link_url, link_options) + $')
  else
    raise "string_with_link: No place for __link__ given in #{str}" if Rails.env.test?
    nil
  end
end
log_in_message: "Already signed up? __Log in!__"

And in my views:

<p><%= string_with_link(t('.log_in_message'), login_path) %></p>

This way it's easier to translate messages as also the link text is clearly defined in the locale.yml-files.

Great solution. I put this into a Gem, which allows you to define things link This is a %{link:link to Google}. It allows you to have multiple links in a single string, takes care of XSS and allowes nested translations. Have a look at github.com/iGEL/i18n_link

i did it with "str = t str" so i just give the translate key in the function. more comfortable!

I would upvote @iGEL more if I could. The project has moved github.com/iGEL/it and if you want to use it in a controller for a flash message in Rails 3+ do it like this view_context.it(key, ...)

Here is a better example for using it in a controller -- github.com/iGEL/it/issues/10

internationalization - rails i18n - translating text with links inside...

ruby-on-rails internationalization
Rectangle 27 26

My app was version 2.3.5. I've now changed it to 2.3.8 and <%= f.label :username %> now uses the translation in:

dk:
  activerecord:
    attributes:
      user:
        username:

I found the hint in this ticket:

What if you want to have a label like 'Enter your first name'? I don't feel setting attribute to a phrase like that is clean, will probably lead to some problems in some specific cases. See Voldy's answer for a correct way to customize a form label. You can even use both approaches together, but Voldy's aproach will override this one on your form, and it should

internationalization - Rails i18n and yml structure for form labels - ...

ruby-on-rails internationalization yaml
Rectangle 27 7

I took hollis solution and made a gem called it out of it. Let's look at an example:

log_in_message: "Already signed up? %{login:Log in!}"
<p><%=t_link "log_in_message", :login => login_path %></p>

internationalization - rails i18n - translating text with links inside...

ruby-on-rails internationalization
Rectangle 27 13

As per 8xx8's comment, a simpler version of:

I18n.t(:foo)
I18n.backend.send(:translations)[:en][:test_string]
I18n.t(".")[:test_string]

This mitigates having to both preload the translations or specify the locale.

I18n.t(".")

internationalization - How to retrieve all translations from yml files...

ruby-on-rails internationalization yaml rails-i18n
Rectangle 27 134

The basic steps (among others) of a java app internationalizing, are Localelizing and resource bundling. In JavaFX, you can use FXMLLoader#setResources() for that purposes. Here a SSCCE demo to demonstrate it. The codes are self-descriptive. Demo package structure:

bundledemo
    |------ BundleDemo.java
    |------ MyController.java
    |------ MyView.fxml  
bundles
    |------ MyBundle_en.properties
    |------ MyBundle_kg.properties
key1=Name Surname
key2=How are you?
key1=A 
key2=?
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.*?>

<BorderPane fx:controller="bundledemo.MyController" xmlns:fx="http://javafx.com/fxml">
    <top>
        <!-- This label's text will be set by the controller -->
        <Label fx:id="lblTextByController"/> 
    </top>
    <center>
        <!-- This label's text will be taken from the bundle automatically -->
        <Label text="%key2"/>
    </center>
</BorderPane>
package bundledemo;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;

public class MyController implements Initializable {

    @FXML private Label lblTextByController;
    private ResourceBundle bundle;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        bundle = resources;
        lblTextByController.setText(bundle.getString("key1"));
    }
}
package bundledemo;
// imports are ignored.

public class BundleDemo extends Application {

    private Stage stage;

    @Override
    public void start(Stage primaryStage) {
        stage = primaryStage;
        Button btnEN = new Button();
        btnEN.setText("English");
        btnEN.setOnAction(new EventHandler<ActionEvent>() {
            @Override public void handle(ActionEvent event) {
                loadView(new Locale("en", "EN"));
            }
        });

        Button btnKG = new Button();
        btnKG.setText("Kyrgyz");
        btnKG.setOnAction(new EventHandler<ActionEvent>() {
            @Override public void handle(ActionEvent event) {
                loadView(new Locale("kg", "KG"));
            }
        });

        VBox root = new VBox(20);
        root.getChildren().add(HBoxBuilder.create().spacing(10).style("-fx-background-color: gray").padding(new Insets(5)).children(btnEN, btnKG).build());
        root.getChildren().add(new StackPane());
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }

    private void loadView(Locale locale) {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader();
            fxmlLoader.setResources(ResourceBundle.getBundle("bundles.MyBundle", locale));
            Pane pane = (BorderPane) fxmlLoader.load(this.getClass().getResource("MyView.fxml").openStream());
            // replace the content
            StackPane content = (StackPane) ((VBox) stage.getScene().getRoot()).getChildren().get(1);
            content.getChildren().clear();
            content.getChildren().add(pane);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Excellent answer and I will accept it as is but I should have mentioned that I'm am building the interface in code rather than FXML. Is there a quick and easy way to internationalize in code, I realize I can do a ResourceBundle.getBundle + lookups but I was hoping there was something like the %key notation that I can be used instead.

Then you can do that in ordinary way like in any other Java application. Determine user's/client's locale then change app's locale accordingly (get lang specific data from DB vs.). Load appropriate bundle by ResourceBundle.getBundle("bundles.MyBundle", locale). Change every text you have used in your view/page by bundle.getString("key").

It is not working for me if I provide a ResourceBundle over the setResources() method. It is working when I provide the ResourceBundle via the load() method.

FXMLLoader.load(getClass().getResource(sceneId), getResources())
sceneId
getResources()

Nice, a variant with the static way like in the oracle tutorial works too (and it is shorter): Pane pane = (BorderPane) FxmlLoader.load(this.getClass().getResource("MyView.fxml"),ResourceBundle.getBundle("bundles.MyBundle", locale));

JavaFX 2 and Internationalization - Stack Overflow

internationalization javafx-2
Rectangle 27 3

Thank you very much, holli, for sharing this approach. It works like a charm for me. Would vote you up if I could, but this is my first post so I'm lacking the proper reputation ... As an additional piece to the puzzle: The problem I realized with your approach is that it still won't work from inside the controller. I did some research and combined your approach with the one from Glenn on rubypond.

def render_flash_messages
    messages = flash.collect do |key, value|
      content_tag(:div, flash_message_with_link(key, value), :class => "flash #{key}") unless key.to_s =~ /_link$/i
    end
    messages.join.html_safe
  end

  def flash_message_with_link(key, value)
    link = flash["#{key}_link".to_sym]
    link.nil? ? value : string_with_link(value, link).html_safe
  end

  # Converts
  # "string with __link__ in the middle." to
  # "string with #{link_to('link', link_url, link_options)} in the middle."
  # --> see http://stackoverflow.com/questions/2543936/rails-i18n-translating-text-with-links-inside (holli)
  def string_with_link(str, link_url, link_options = {})
    match = str.match(/__([^_]{2,30})__/)
    if !match.blank?
      $` + link_to($1, link_url, link_options) + $'
    else
      raise "string_with_link: No place for __link__ given in #{str}" if Rails.env.test?
      nil
    end
  end
flash.now[:alert] = t("path.to.translation")
flash.now[:alert_link] = here_comes_the_link_path # or _url
path:
  to:
    translation: "string with __link__ in the middle"
<%= render_flash_messages %>

internationalization - rails i18n - translating text with links inside...

ruby-on-rails internationalization
Rectangle 27 3

registration:
    terms:
      text: "I do agree with the terms and conditions: %{gtc} / %{stc}"
      gtc: "GTC"
      stc: "STC"
registration:
    terms:
      text: "Ich stimme den Geschfts- und Nutzungsbedingungen zu: %{gtc} / %{stc}"
      gtc: "AGB"
      stc: "ANB"
<%= t(
   'registration.terms.text',
    gtc:  link_to(t('registration.terms.gtc'),  terms_and_conditions_home_index_url + "?tab=gtc"),
    stc: link_to(t('registration.terms.stc'), terms_and_conditions_home_index_url + "?tab=stc")
 ).html_safe %>

internationalization - rails i18n - translating text with links inside...

ruby-on-rails internationalization
Rectangle 27 11

I would propose to keep one bundle-message-source in a new bean and inject it into your DatabaseMessageSource.

// Place your Spring DSL code here
beans = {
    messageSource(DatabaseMessageSource) {
        messageBundleMessageSource = ref("messageBundleMessageSource")
    }    
    messageBundleMessageSource(org.codehaus.groovy.grails.context.support.PluginAwareResourceBundleMessageSource) {
        basenames = "WEB-INF/grails-app/i18n/messages"
    }
}
class DatabaseMessageSource extends AbstractMessageSource {

    def messageBundleMessageSource

    protected MessageFormat resolveCode(String code, Locale locale) {
         Message msg = Message.findByCodeAndLocale(code, locale)
         def format
         if(msg) {
             format = new MessageFormat(msg.text, msg.locale)
         }
         else {
             format = messageBundleMessageSource.resolveCode(code, locale)
         }
         return format;
    }
}

This way, in fallback solution, the message will be read from the appropriate messages_*.properties file, by just requesting it from one resource bundle message source. Note that you should use the PluginAwareResourceBundleMessageSource, otherwise you could miss some important messages from your plugins.

internationalization - Grails i18n From Database but Default Back To F...

grails internationalization
Rectangle 27 2

module I18nHelpers
  def translate key, options={}, &block
    s = super key, options  # Default translation
    if block_given?
      String.new(ERB::Util.html_escape(s)).gsub(/%\|([^\|]*)\|/){
        capture($1, &block)  # Pass in what's between the markers
      }.html_safe
    else
      s
    end
  end
  alias :t :translate
end
module I18nHelpers

  # Allows an I18n to include the special %|something| marker.
  # "something" will then be passed in to the given block, which
  # can generate whatever HTML is needed.
  #
  # Normal and _html keys are supported.
  #
  # Multiples are ok
  #
  #     mykey:  "Click %|here| and %|there|"
  #
  # Nesting should work too.
  #
  def translate key, options={}, &block

    s = super key, options  # Default translation

    if block_given?

      # Escape if not already raw HTML (html_escape won't escape if already html_safe)
      s = ERB::Util.html_escape(s)

      # ActiveSupport::SafeBuffer#gsub broken, so convert to String.
      # See https://github.com/rails/rails/issues/1555
      s = String.new(s)

      # Find the %|| pattern to substitute, then replace it with the block capture
      s = s.gsub /%\|([^\|]*)\|/ do
        capture($1, &block)  # Pass in what's between the markers
      end

      # Mark as html_safe going out
      s = s.html_safe
    end

    s
  end
  alias :t :translate


end

then in ApplicationController.rb just

class ApplicationController < ActionController::Base
  helper I18nHelpers

Given a key in the en.yml file like

mykey: "Click %|here|!"

can be used in ERB as

<%= t '.mykey' do |text| %>
  <%= link_to text, 'http://foo.com' %>
<% end %>
Click <a href="http://foo.com">here</a>!

internationalization - rails i18n - translating text with links inside...

ruby-on-rails internationalization
Rectangle 27 13

getLanguageNativeName("cv"); // --> " "
getLanguageName("cv"); // --> "Chuvash"
getLanguageNativeName("cv-RU"); // --> " "
getLanguageName("cv-RU"); // --> "Chuvash"

This is almost it. But it only shows the language name in two languages. For instance, there is a dropbown on my site to associate a language to some content. If a french guy uses my site and want to select "german", it should show "allemand" (french name for the german language). Same for a chinese visitor etc.

internationalization - Language name from ISO 639-1 code in Javascript...

javascript internationalization
Rectangle 27 149

Localisation support in legacy browsers is poor. Originally, this was due to phrases in the ECMAScript language spec that look like this:

Number.prototype.toLocaleString() Produces a string value that represents the value of the Number formatted according to the conventions of the host environments current locale. This function is implementation-dependent, and it is permissible, but not encouraged, for it to return the same thing as toString.

Every localisation method defined in the spec is defined as "implementation-dependent", which results in a lot of inconsistencies. In this instance, Chrome Opera and Safari would return the same thing as .toString(). Firefox and IE will return locale formatted strings, and IE even includes a thousands separator (perfect for currency strings). Chrome was recently updated to return a thousands-separated string, though with no fixed decimal.

For modern environments, the ECMAScript Internationalization API spec, a new standard that complements the ECMAScript Language spec, provides much better support for string comparison, number formatting, and date and time formatting; it also fixes the corresponding functions in the Language Spec. An introduction can be found here. Implementations are available in:

There is also a compatibility implementation, Intl.js, which will provide the API in environments where it doesn't already exist.

Determining the user's preferred language remains a problem, since there's no specification for obtaining the current language. Each browser implements a method to obtain a language string, but this could be based on the user's operating system language or just the language of the browser:

// navigator.userLanguage for IE, navigator.language for others
var lang = navigator.language || navigator.userLanguage;

A good workaround for this is to dump the Accept-Language header from the server to the client. If formatted as a JavaScript, it can be passed to the Internationalization API constructors, which will automatically pick the best (or first-supported) locale.

In short, you have to put in a lot of the work yourself, or use a framework/library, because you cannot rely on the browser to do it for you.

Various libraries and plugins for localisation:

  • Intl.js - a compatibility implementation of the Internationalisation API
  • browser-i18n with support to pluralization
  • requirejs-i18n Define an I18N Bundle with RequireJS.

Thanks to all the people contributing; I'd never have thought I could learn something by reading my old answers. I'm glad to see the update for Internationalization API spec in there, that's really awesome and I just got to test drive it in Chrome.

Thanks for the excellent compilation. On a positive note, it looks like Mozilla might ship a modern toLocaleString() soon possibly FF28: bugzilla.mozilla.org/show_bug.cgi?id=769871

i18next.com now comes with a translation management built on top locize.com - this might be a big win if you need to solve the complete translation process - not just instrument your code for i18n. Plus has a nice Incontext Editor feature...

How does internationalization work in JavaScript? - Stack Overflow

javascript internationalization
Rectangle 27 11

src
    app
    bundles // <- here the "bundles"
    dicts
    images
    libs
    resources

In the bundles package are

LangBundle_en.properties
LangBundle_de.properties
enter_pwd=Enter your password:

To load them I use the following code:

@Override
public void initialize(URL location, ResourceBundle resources) {
    ResourceBundle lngBndl = ResourceBundle
            .getBundle("bundles.LangBundle", new Locale("en", "EN"));

    tvSetupPwd.setText(lngBndl.getString("enter_pwd"));
    // ...
}

JavaFX 2 and Internationalization - Stack Overflow

internationalization javafx-2
Rectangle 27 134

Android 2.1 does not have Arabic font.

Android 2.2 has Arabic font but does not show your word correctly.

Farsi.GetFarsiFont(this)
Farsi.Convert("")

For Android 2.2 you do not need setting font but must use Farsi.Convert("")

And for Android 3.x forget all of the above solutions ;). But you can change the font if you do not like the 3.x Arabic font.

so do the following steps:

2) use the following class to get the font and converting your Arabic or Farsi text to a good form for showing in your activities.

import android.content.Context;
import android.graphics.Typeface;

public final class Farsi {

    public static boolean isFarsiConversionNeeded = true;

    private final static String szLamAndAlef = Character
            .toString((char) 0xfedf)
            + Character.toString((char) 0xfe8e); // Lam + Alef

    private final static String szLamStickAndAlef = Character
            .toString((char) 0xfee0)
            + Character.toString((char) 0xfe8e); // Lam (Sticky !!!)+
                                                    // Alef

    private final static String szLa = Character.toString((char) 0xfefb); // La
    private final static String szLaStick = Character.toString((char) 0xfefc); // La
                                                                                // (Sticky!!!)

    private final static String szLamAndAlefWoosim = Character
            .toString((char) 0xe1)
            + Character.toString((char) 0xbb); // Lam + Alef

    private final static String szLamStickAndAlefWoosim = Character
            .toString((char) 0x90)
            + Character.toString((char) 0xbb); // Lam (Sticky !!!)+
                                                // Alef

    private final static String szLaWoosim = Character.toString((char) 0xd9); // La
    private final static String szLaStickWoosim = Character
            .toString((char) 0xd9); // La

    // (Sticky!!!)

    private static final class struc {
        public char character;
        public char endGlyph;
        public char iniGlyph;
        public char midGlyph;
        public char isoGlyph;

        public struc(char Character, char EndGlyph, char IniGlyph,
                char MidGlyph, char IsoGlyph) {
            character = Character;
            endGlyph = EndGlyph;
            iniGlyph = IniGlyph;
            midGlyph = MidGlyph;
            isoGlyph = IsoGlyph;
        }
    }

    static struc[] arrStruc = {
            new struc((char) 0x630, (char) 0xfeac, (char) 0xfeab,
                    (char) 0xfeac, (char) 0xfeab),
            new struc((char) 0x62f, (char) 0xfeaa, (char) 0xfea9,
                    (char) 0xfeaa, (char) 0xfea9),
            new struc((char) 0x62c, (char) 0xfe9e, (char) 0xfe9f,
                    (char) 0xfea0, (char) 0xfe9d),
            new struc((char) 0x62d, (char) 0xfea2, (char) 0xfea3,
                    (char) 0xfea4, (char) 0xfea1),
            new struc((char) 0x62e, (char) 0xfea6, (char) 0xfea7,
                    (char) 0xfea8, (char) 0xfea5),
            new struc((char) 0x647, (char) 0xfeea, (char) 0xfeeb,
                    (char) 0xfeec, (char) 0xfee9),
            new struc((char) 0x639, (char) 0xfeca, (char) 0xfecb,
                    (char) 0xfecc, (char) 0xfec9),
            new struc((char) 0x63a, (char) 0xfece, (char) 0xfecf,
                    (char) 0xfed0, (char) 0xfecd),
            new struc((char) 0x641, (char) 0xfed2, (char) 0xfed3,
                    (char) 0xfed4, (char) 0xfed1),
            new struc((char) 0x642, (char) 0xfed6, (char) 0xfed7,
                    (char) 0xfed8, (char) 0xfed5),
            new struc((char) 0x62b, (char) 0xfe9a, (char) 0xfe9b,
                    (char) 0xfe9c, (char) 0xfe99),
            new struc((char) 0x635, (char) 0xfeba, (char) 0xfebb,
                    (char) 0xfebc, (char) 0xfeb9),
            new struc((char) 0x636, (char) 0xfebe, (char) 0xfebf,
                    (char) 0xfec0, (char) 0xfebd),
            new struc((char) 0x637, (char) 0xfec2, (char) 0xfec3,
                    (char) 0xfec4, (char) 0xfec1),
            new struc((char) 0x643, (char) 0xfeda, (char) 0xfedb,
                    (char) 0xfedc, (char) 0xfed9),
            new struc((char) 0x645, (char) 0xfee2, (char) 0xfee3,
                    (char) 0xfee4, (char) 0xfee1),
            new struc((char) 0x646, (char) 0xfee6, (char) 0xfee7,
                    (char) 0xfee8, (char) 0xfee5),
            new struc((char) 0x62a, (char) 0xfe96, (char) 0xfe97,
                    (char) 0xfe98, (char) 0xfe95),
            new struc((char) 0x627, (char) 0xfe8e, (char) 0xfe8d,
                    (char) 0xfe8e, (char) 0xfe8d),
            new struc((char) 0x644, (char) 0xfede, (char) 0xfedf,
                    (char) 0xfee0, (char) 0xfedd),
            new struc((char) 0x628, (char) 0xfe90, (char) 0xfe91,
                    (char) 0xfe92, (char) 0xfe8f),
            new struc((char) 0x64a, (char) 0xfef2, (char) 0xfef3,
                    (char) 0xfef4, (char) 0xfef1),
            new struc((char) 0x633, (char) 0xfeb2, (char) 0xfeb3,
                    (char) 0xfeb4, (char) 0xfeb1),
            new struc((char) 0x634, (char) 0xfeb6, (char) 0xfeb7,
                    (char) 0xfeb8, (char) 0xfeb5),
            new struc((char) 0x638, (char) 0xfec6, (char) 0xfec7,
                    (char) 0xfec8, (char) 0xfec5),
            new struc((char) 0x632, (char) 0xfeb0, (char) 0xfeaf,
                    (char) 0xfeb0, (char) 0xfeaf),
            new struc((char) 0x648, (char) 0xfeee, (char) 0xfeed,
                    (char) 0xfeee, (char) 0xfeed),
            new struc((char) 0x629, (char) 0xfe94, (char) 0xfe93,
                    (char) 0xfe93, (char) 0xfe93),
            new struc((char) 0x649, (char) 0xfef0, (char) 0xfeef,
                    (char) 0xfef0, (char) 0xfeef),
            new struc((char) 0x631, (char) 0xfeae, (char) 0xfead,
                    (char) 0xfeae, (char) 0xfead),
            new struc((char) 0x624, (char) 0xfe86, (char) 0xfe85,
                    (char) 0xfe86, (char) 0xfe85),
            new struc((char) 0x621, (char) 0xfe80, (char) 0xfe80,
                    (char) 0xfe80, (char) 0xfe80),
            new struc((char) 0x626, (char) 0xfe8a, (char) 0xfe8b,
                    (char) 0xfe8c, (char) 0xfe89),
            new struc((char) 0x623, (char) 0xfe84, (char) 0xfe83,
                    (char) 0xfe84, (char) 0xfe83),
            new struc((char) 0x622, (char) 0xfe82, (char) 0xfe81,
                    (char) 0xfe82, (char) 0xfe81),
            new struc((char) 0x625, (char) 0xfe88, (char) 0xfe87,
                    (char) 0xfe88, (char) 0xfe87),
            new struc((char) 0x67e, (char) 0xfb57, (char) 0xfb58,
                    (char) 0xfb59, (char) 0xfb56), // peh
            new struc((char) 0x686, (char) 0xfb7b, (char) 0xfb7c,
                    (char) 0xfb7d, (char) 0xfb7a), // cheh
            new struc((char) 0x698, (char) 0xfb8b, (char) 0xfb8a,
                    (char) 0xfb8b, (char) 0xfb8a), // jeh
            new struc((char) 0x6a9, (char) 0xfb8f, (char) 0xfb90,
                    (char) 0xfb91, (char) 0xfb8e), // keheh
            new struc((char) 0x6af, (char) 0xfb93, (char) 0xfb94,
                    (char) 0xfb95, (char) 0xfb92), // gaf
            // new struc((char) 0x6cc, (char) 0xfbfd, (char) 0xfbfe,
            // (char) 0xfbff, (char) 0xfbfc), // Farsi yeh
            new struc((char) 0x6cc, (char) 0xfbfd, (char) 0xfef3,
                    (char) 0xfef4, (char) 0xfbfc), // Arabic yeh
            new struc((char) 0x6c0, (char) 0xfba5, (char) 0xfba4,
                    (char) 0xfba5, (char) 0xfba4) // heh with yeh
    };

    static struc[] arrStrucWoosim = {
            new struc((char) 0x630, (char) 0xb5, (char) 0x82, (char) 0xb5,
                    (char) 0x82),
            new struc((char) 0x62f, (char) 0xb4, (char) 0x81, (char) 0xb4,
                    (char) 0x81),
            new struc((char) 0x62c, (char) 0x9b, (char) 0xb1, (char) 0xf9,
                    (char) 0xbf),
            new struc((char) 0x62d, (char) 0x9c, (char) 0xb2, (char) 0xfa,
                    (char) 0xc0),
            new struc((char) 0x62e, (char) 0x9d, (char) 0xb3, (char) 0xfe,
                    (char) 0xc1),
            new struc((char) 0x647, (char) 0xac, (char) 0xe4, (char) 0x93,
                    (char) 0xd5),
            new struc((char) 0x639, (char) 0xc9, (char) 0xd3, (char) 0x8b,
                    (char) 0xa4),
            new struc((char) 0x63a, (char) 0xca, (char) 0xdd, (char) 0x8c,
                    (char) 0xa5),
            new struc((char) 0x641, (char) 0xa6, (char) 0xde, (char) 0x8d,
                    (char) 0xcc),
            new struc((char) 0x642, (char) 0xa7, (char) 0xdf, (char) 0x8e,
                    (char) 0xce),
            new struc((char) 0x62b, (char) 0xbd, (char) 0xaf, (char) 0xea,
                    (char) 0x99),
            new struc((char) 0x635, (char) 0xc4, (char) 0xc8, (char) 0x87,
                    (char) 0xa0),
            new struc((char) 0x636, (char) 0xc5, (char) 0xcb, (char) 0x88,
                    (char) 0xa1),
            new struc((char) 0x637, (char) 0xc6, (char) 0xcd, (char) 0xcd,
                    (char) 0xa2),
            new struc((char) 0x643, (char) 0xcf, (char) 0xe0, (char) 0x8f,
                    (char) 0xa8),
            new struc((char) 0x645, (char) 0xd2, (char) 0xe2, (char) 0x91,
                    (char) 0xaa),
            new struc((char) 0x646, (char) 0xd4, (char) 0xe3, (char) 0x92,
                    (char) 0xab),
            new struc((char) 0x62a, (char) 0xbd, (char) 0xaf, (char) 0xea,
                    (char) 0x99),
            new struc((char) 0x627, (char) 0xbb, (char) 0x80, (char) 0xbb,
                    (char) 0x80),
            new struc((char) 0x644, (char) 0xd1, (char) 0xe1, (char) 0x90,
                    (char) 0xa9),
            new struc((char) 0x628, (char) 0xbc, (char) 0xae, (char) 0xe9,
                    (char) 0x98),
            new struc((char) 0x64a, (char) 0xdc, (char) 0xe6, (char) 0x95,
                    (char) 0xdc),
            new struc((char) 0x633, (char) 0xc2, (char) 0xb8, (char) 0xb8,
                    (char) 0x9e),
            new struc((char) 0x634, (char) 0xc3, (char) 0xb9, (char) 0xb9,
                    (char) 0x9f),
            new struc((char) 0x638, (char) 0xc7, (char) 0xcd, (char) 0xcd,
                    (char) 0xc7),
            new struc((char) 0x632, (char) 0xb7, (char) 0xb7, (char) 0xb7,
                    (char) 0xb7),
            new struc((char) 0x648, (char) 0x94, (char) 0x94, (char) 0x94,
                    (char) 0x94),
            new struc((char) 0x629, (char) 0xda, (char) 0xda, (char) 0xda,
                    (char) 0xda),
            new struc((char) 0x649, (char) 0xdc, (char) 0xe6, (char) 0x95,
                    (char) 0xdc),
            new struc((char) 0x631, (char) 0xb6, (char) 0xb6, (char) 0xb6,
                    (char) 0xb6),
            new struc((char) 0x624, (char) 0xe7, (char) 0xe7, (char) 0xe7,
                    (char) 0xe7),
            new struc((char) 0x621, (char) 0xba, (char) 0xba, (char) 0xba,
                    (char) 0xba),
            new struc((char) 0x626, (char) 0xd7, (char) 0xe8, (char) 0x97,
                    (char) 0xd7),
            new struc((char) 0x623, (char) 0x80, (char) 0x80, (char) 0x80,
                    (char) 0x80),
            new struc((char) 0x622, (char) 0x80, (char) 0x80, (char) 0x80,
                    (char) 0x80),
            new struc((char) 0x625, (char) 0x80, (char) 0x80, (char) 0x80,
                    (char) 0x80),
            new struc((char) 0x67e, (char) 0xbc, (char) 0xae, (char) 0xe9,
                    (char) 0x98), // peh
            new struc((char) 0x686, (char) 0x9b, (char) 0xb1, (char) 0xf9,
                    (char) 0xbf), // cheh
            new struc((char) 0x698, (char) 0xb7, (char) 0xb7, (char) 0xb7,
                    (char) 0xb7), // jeh
            new struc((char) 0x6a9, (char) 0xcf, (char) 0xe0, (char) 0x8f,
                    (char) 0xa8), // keheh
            new struc((char) 0x6af, (char) 0xcf, (char) 0xe0, (char) 0x8f,
                    (char) 0xa8), // gaf
            new struc((char) 0x6cc, (char) 0xdc, (char) 0xe6, (char) 0x95,
                    (char) 0xdc), // yeh
            new struc((char) 0x6c0, (char) 0xac, (char) 0xe4, (char) 0x93,
                    (char) 0xd5) // heh with yeh
    };

    private static final int N_DISTINCT_CHARACTERS = 43;

    private static final String ArabicReverse(String s) {
        try {
            String Out = "", rev;
            s = MakeReverse(s);
            char[] chs = new char[s.length()];
            chs = s.toCharArray();
            int i = 0;
            while (i < s.length()) {
                if ((chs[i] >= '0' && chs[i] <= '9')) // isDigit(s[i]) ?
                {
                    rev = "";
                    while (i < s.length()
                            && ((chs[i] >= '0' && chs[i] <= '9') || chs[i] == '/')) // isDigit(s[i])
                                                                                    // ?
                    {
                        rev = rev + chs[i];
                        ++i;
                    }
                    rev = MakeReverse(rev);
                    Out = Out + rev;
                } else {
                    Out = Out + chs[i];
                    ++i;
                }
            }
            s = Out;
        } catch (Exception ex) {
            // throw new Exception(
            // "An exception has occurred in ArabicReverse function.\\n"
            // + ex.getMessage());
        }
        return s;
    }

    private static final boolean isFromTheSet1(/* WCHAR */char ch) {
        char[] theSet1 = new char[] { (char) 0x62c, (char) 0x62d, (char) 0x62e,
                (char) 0x647, (char) 0x639, (char) 0x63a, (char) 0x641,
                (char) 0x642, (char) 0x62b, (char) 0x635, (char) 0x636,
                (char) 0x637, (char) 0x643, (char) 0x645, (char) 0x646,
                (char) 0x62a, (char) 0x644, (char) 0x628, (char) 0x64a,
                (char) 0x633, (char) 0x634, (char) 0x638, (char) 0x67e,
                (char) 0x686, (char) 0x6a9, (char) 0x6af, (char) 0x6cc,
                (char) 0x626 };
        int i = 0;
        while (i < 28) {
            if (ch == theSet1[i])
                return true;
            ++i;
        }
        return false;
    }

    private static final boolean isFromTheSet2(/* WCHAR */char ch) {
        char[] theSet2 = new char[] { (char) 0x627, (char) 0x623, (char) 0x625,
                (char) 0x622, (char) 0x62f, (char) 0x630, (char) 0x631,
                (char) 0x632, (char) 0x648, (char) 0x624, (char) 0x629,
                (char) 0x649, (char) 0x698, (char) 0x6c0 };
        int i = 0;
        while (i < 14) {
            if (ch == theSet2[i])
                return true;
            ++i;
        }
        return false;
    }

    private static final String MakeReverse(String text) {
        String Result = "";
        char[] Ctext = new char[text.length()];
        Ctext = text.toCharArray();
        for (int i = (text.length()) - 1; i >= 0; i--) {
            Result += Ctext[i];
        }
        return Result;
    }

    public static final String ConvertBackToRealFarsi(String In) {

        if (!isFarsiConversionNeeded) {
            return In;
        }

        String strOut = "";
        StringBuilder strBuilder = new StringBuilder("");
        int i = 0;
        int j = 0;
        char[] chIn = new char[In.length()];
        chIn = In.toCharArray();

        for (i = 0; i < In.length(); i++) {
            boolean found = false;
            for (j = 0; j < arrStruc.length; j++) {
                if (chIn[i] == arrStruc[j].midGlyph ||
                        chIn[i] == arrStruc[j].iniGlyph ||
                        chIn[i] == arrStruc[j].endGlyph ||
                        chIn[i] == arrStruc[j].isoGlyph) {
                    strBuilder.append(arrStruc[j].character);
                    found = true;
                    break;
                }
            }
            if (!found)
                strBuilder.append(chIn[i]);
        }

        strOut = strBuilder.toString();
    strOut = strOut.replace(szLa, "");
    strOut = strOut.replace(szLaStick, "");

        return strOut;
    }

    public static final String Convert(String In) {

        if (!isFarsiConversionNeeded) {
            return In;
        }

        if (In == null) {
            return "";
        }

        boolean linkBefore, linkAfter;
        String Out = In;
        char[] chOut = new char[Out.length()];
        chOut = Out.toCharArray();
        char[] chIn = new char[In.length()];
        chIn = In.toCharArray();

        for (int i = 0; i < In.length(); i++) {
            /* WCHAR */
            char ch = chIn[i];
            if ((ch >= (char) 0x0621 && ch <= (char) 0x064a)
                    || (ch == (char) 0x067e) || (ch == (char) 0x0686)
                    || (ch == (char) 0x0698) || (ch == (char) 0x06a9)
                    || (ch == (char) 0x06af) || (ch == (char) 0x06cc)
                    || (ch == (char) 0x06c0)) // is a Farsi character?
            {
                int idx = 0;
                while (idx < N_DISTINCT_CHARACTERS) {
                    if (arrStruc[idx].character == chIn[i])
                        break;
                    ++idx;
                }

                if (i == In.length() - 1)
                    linkAfter = false;
                else
                    linkAfter = (isFromTheSet1(chIn[i + 1]) || isFromTheSet2(chIn[i + 1]));
                if (i == 0)
                    linkBefore = false;
                else
                    linkBefore = isFromTheSet1(chIn[i - 1]);
                if (idx < N_DISTINCT_CHARACTERS) {
                    if (linkBefore && linkAfter)
                        chOut[i] = arrStruc[idx].midGlyph;
                    if (linkBefore && !linkAfter)
                        chOut[i] = arrStruc[idx].endGlyph;
                    if (!linkBefore && linkAfter)
                        chOut[i] = arrStruc[idx].iniGlyph;
                    if (!linkBefore && !linkAfter)
                        chOut[i] = arrStruc[idx].isoGlyph;
                } else {
                    chOut[i] = chIn[i];
                }
            } else {
                chOut[i] = chIn[i];
            }
        }
        Out = "";
        for (int j = 0; j < chOut.length; j++)
            Out += chOut[j];
        // Out = ArabicReverse(Out);

        Out = Out.replace((char) 0x200c, ' '); // Change NO SPACE to SPACE

        Out = Out.replace(szLamAndAlef, szLa); // Join 'Lam' and 'Alef' and
                                                // make 'La'
        Out = Out.replace(szLamStickAndAlef, szLaStick); // Join 'Lam Stick'
                                                            // and 'Alef'
                                                            // and make 'La
                                                            // Stick'

        return reorderWords(Out);

    }

    private final static String reorderWords(String strIn)
    {

        final int ST_RTL = 0;
        final int ST_LTR = 1;

        String strOut = "";
        String prevWord = "";
        int state = ST_RTL;
        char[] arr = strIn.toCharArray();
        int i = 0;
        while (i < arr.length) {
            if (charIsLTR(arr[i]) && state != ST_LTR)
            {
                // state changed to LTR
                state = ST_LTR;
                strOut = prevWord + strOut;
                prevWord = "";
                prevWord += arr[i];
            }
            else if (charIsRTL(arr[i]) && state != ST_RTL)
            {
                // state changed to RTL
                state = ST_RTL;
                strOut = prevWord + strOut;
                prevWord = "";
                prevWord += arr[i];
            }
            else
            {
                // state is not changed
                prevWord += arr[i];
            }
            i++;
        }

        strOut = prevWord + strOut;

        return strOut;

    }

    private final static boolean charIsLTR(char ch)
    {
        return (ch >= (char) 65 & ch <= (char) 122)
                |
                Character.isDigit(ch);
    }

    private final static boolean charIsRTL(char ch)
    {
        return ch >= (char) 0x0621;
    }   

    private static Typeface typeface;

    public static final Typeface GetFarsiFont(Context context) {
        if (typeface == null) {
            typeface = Typeface.createFromAsset(context.getAssets(),
                    // "DroidSansFallback.ttf");
                    "TAHOMA.TTF");
        }
        return typeface;
    }
}

3) And in your Activity:

Typeface tf = Farsi.GetFarsiFont(this);
MyTextView.setTypeface(tf);
MyTextView.setText(Farsi.Convert(""));

please do not add lots of "follow this link" posts as answers on other questions; a link by itself is not really an answer. I have converted them to comments, so they will still show as related, but without the need for empty answers.

@totti roma: you are getting Exception Because "tahoma.ttf" Written In Caps in that Code and Your File name mighrt not be in caps. Change this and try again

Thanks a lot, it saves a lot of time while I am searching for ROM with Arabic support

@breceivemail .. I was having an exception when I have more than two TextView in one Layout. I used another library and solved the problem github.com/agawish/Better-Arabic-Reshaper/commits/master

@Tina Yes I think it is a bug. I have asked about it in this link: stackoverflow.com/q/7426266/779408

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

internationalization - How to support Arabic text in Android? - Stack ...

android internationalization arabic persian farsi
Rectangle 27 134

Android 2.1 does not have Arabic font.

Android 2.2 has Arabic font but does not show your word correctly.

Farsi.GetFarsiFont(this)
Farsi.Convert("")

For Android 2.2 you do not need setting font but must use Farsi.Convert("")

And for Android 3.x forget all of the above solutions ;). But you can change the font if you do not like the 3.x Arabic font.

so do the following steps:

2) use the following class to get the font and converting your Arabic or Farsi text to a good form for showing in your activities.

import android.content.Context;
import android.graphics.Typeface;

public final class Farsi {

    public static boolean isFarsiConversionNeeded = true;

    private final static String szLamAndAlef = Character
            .toString((char) 0xfedf)
            + Character.toString((char) 0xfe8e); // Lam + Alef

    private final static String szLamStickAndAlef = Character
            .toString((char) 0xfee0)
            + Character.toString((char) 0xfe8e); // Lam (Sticky !!!)+
                                                    // Alef

    private final static String szLa = Character.toString((char) 0xfefb); // La
    private final static String szLaStick = Character.toString((char) 0xfefc); // La
                                                                                // (Sticky!!!)

    private final static String szLamAndAlefWoosim = Character
            .toString((char) 0xe1)
            + Character.toString((char) 0xbb); // Lam + Alef

    private final static String szLamStickAndAlefWoosim = Character
            .toString((char) 0x90)
            + Character.toString((char) 0xbb); // Lam (Sticky !!!)+
                                                // Alef

    private final static String szLaWoosim = Character.toString((char) 0xd9); // La
    private final static String szLaStickWoosim = Character
            .toString((char) 0xd9); // La

    // (Sticky!!!)

    private static final class struc {
        public char character;
        public char endGlyph;
        public char iniGlyph;
        public char midGlyph;
        public char isoGlyph;

        public struc(char Character, char EndGlyph, char IniGlyph,
                char MidGlyph, char IsoGlyph) {
            character = Character;
            endGlyph = EndGlyph;
            iniGlyph = IniGlyph;
            midGlyph = MidGlyph;
            isoGlyph = IsoGlyph;
        }
    }

    static struc[] arrStruc = {
            new struc((char) 0x630, (char) 0xfeac, (char) 0xfeab,
                    (char) 0xfeac, (char) 0xfeab),
            new struc((char) 0x62f, (char) 0xfeaa, (char) 0xfea9,
                    (char) 0xfeaa, (char) 0xfea9),
            new struc((char) 0x62c, (char) 0xfe9e, (char) 0xfe9f,
                    (char) 0xfea0, (char) 0xfe9d),
            new struc((char) 0x62d, (char) 0xfea2, (char) 0xfea3,
                    (char) 0xfea4, (char) 0xfea1),
            new struc((char) 0x62e, (char) 0xfea6, (char) 0xfea7,
                    (char) 0xfea8, (char) 0xfea5),
            new struc((char) 0x647, (char) 0xfeea, (char) 0xfeeb,
                    (char) 0xfeec, (char) 0xfee9),
            new struc((char) 0x639, (char) 0xfeca, (char) 0xfecb,
                    (char) 0xfecc, (char) 0xfec9),
            new struc((char) 0x63a, (char) 0xfece, (char) 0xfecf,
                    (char) 0xfed0, (char) 0xfecd),
            new struc((char) 0x641, (char) 0xfed2, (char) 0xfed3,
                    (char) 0xfed4, (char) 0xfed1),
            new struc((char) 0x642, (char) 0xfed6, (char) 0xfed7,
                    (char) 0xfed8, (char) 0xfed5),
            new struc((char) 0x62b, (char) 0xfe9a, (char) 0xfe9b,
                    (char) 0xfe9c, (char) 0xfe99),
            new struc((char) 0x635, (char) 0xfeba, (char) 0xfebb,
                    (char) 0xfebc, (char) 0xfeb9),
            new struc((char) 0x636, (char) 0xfebe, (char) 0xfebf,
                    (char) 0xfec0, (char) 0xfebd),
            new struc((char) 0x637, (char) 0xfec2, (char) 0xfec3,
                    (char) 0xfec4, (char) 0xfec1),
            new struc((char) 0x643, (char) 0xfeda, (char) 0xfedb,
                    (char) 0xfedc, (char) 0xfed9),
            new struc((char) 0x645, (char) 0xfee2, (char) 0xfee3,
                    (char) 0xfee4, (char) 0xfee1),
            new struc((char) 0x646, (char) 0xfee6, (char) 0xfee7,
                    (char) 0xfee8, (char) 0xfee5),
            new struc((char) 0x62a, (char) 0xfe96, (char) 0xfe97,
                    (char) 0xfe98, (char) 0xfe95),
            new struc((char) 0x627, (char) 0xfe8e, (char) 0xfe8d,
                    (char) 0xfe8e, (char) 0xfe8d),
            new struc((char) 0x644, (char) 0xfede, (char) 0xfedf,
                    (char) 0xfee0, (char) 0xfedd),
            new struc((char) 0x628, (char) 0xfe90, (char) 0xfe91,
                    (char) 0xfe92, (char) 0xfe8f),
            new struc((char) 0x64a, (char) 0xfef2, (char) 0xfef3,
                    (char) 0xfef4, (char) 0xfef1),
            new struc((char) 0x633, (char) 0xfeb2, (char) 0xfeb3,
                    (char) 0xfeb4, (char) 0xfeb1),
            new struc((char) 0x634, (char) 0xfeb6, (char) 0xfeb7,
                    (char) 0xfeb8, (char) 0xfeb5),
            new struc((char) 0x638, (char) 0xfec6, (char) 0xfec7,
                    (char) 0xfec8, (char) 0xfec5),
            new struc((char) 0x632, (char) 0xfeb0, (char) 0xfeaf,
                    (char) 0xfeb0, (char) 0xfeaf),
            new struc((char) 0x648, (char) 0xfeee, (char) 0xfeed,
                    (char) 0xfeee, (char) 0xfeed),
            new struc((char) 0x629, (char) 0xfe94, (char) 0xfe93,
                    (char) 0xfe93, (char) 0xfe93),
            new struc((char) 0x649, (char) 0xfef0, (char) 0xfeef,
                    (char) 0xfef0, (char) 0xfeef),
            new struc((char) 0x631, (char) 0xfeae, (char) 0xfead,
                    (char) 0xfeae, (char) 0xfead),
            new struc((char) 0x624, (char) 0xfe86, (char) 0xfe85,
                    (char) 0xfe86, (char) 0xfe85),
            new struc((char) 0x621, (char) 0xfe80, (char) 0xfe80,
                    (char) 0xfe80, (char) 0xfe80),
            new struc((char) 0x626, (char) 0xfe8a, (char) 0xfe8b,
                    (char) 0xfe8c, (char) 0xfe89),
            new struc((char) 0x623, (char) 0xfe84, (char) 0xfe83,
                    (char) 0xfe84, (char) 0xfe83),
            new struc((char) 0x622, (char) 0xfe82, (char) 0xfe81,
                    (char) 0xfe82, (char) 0xfe81),
            new struc((char) 0x625, (char) 0xfe88, (char) 0xfe87,
                    (char) 0xfe88, (char) 0xfe87),
            new struc((char) 0x67e, (char) 0xfb57, (char) 0xfb58,
                    (char) 0xfb59, (char) 0xfb56), // peh
            new struc((char) 0x686, (char) 0xfb7b, (char) 0xfb7c,
                    (char) 0xfb7d, (char) 0xfb7a), // cheh
            new struc((char) 0x698, (char) 0xfb8b, (char) 0xfb8a,
                    (char) 0xfb8b, (char) 0xfb8a), // jeh
            new struc((char) 0x6a9, (char) 0xfb8f, (char) 0xfb90,
                    (char) 0xfb91, (char) 0xfb8e), // keheh
            new struc((char) 0x6af, (char) 0xfb93, (char) 0xfb94,
                    (char) 0xfb95, (char) 0xfb92), // gaf
            // new struc((char) 0x6cc, (char) 0xfbfd, (char) 0xfbfe,
            // (char) 0xfbff, (char) 0xfbfc), // Farsi yeh
            new struc((char) 0x6cc, (char) 0xfbfd, (char) 0xfef3,
                    (char) 0xfef4, (char) 0xfbfc), // Arabic yeh
            new struc((char) 0x6c0, (char) 0xfba5, (char) 0xfba4,
                    (char) 0xfba5, (char) 0xfba4) // heh with yeh
    };

    static struc[] arrStrucWoosim = {
            new struc((char) 0x630, (char) 0xb5, (char) 0x82, (char) 0xb5,
                    (char) 0x82),
            new struc((char) 0x62f, (char) 0xb4, (char) 0x81, (char) 0xb4,
                    (char) 0x81),
            new struc((char) 0x62c, (char) 0x9b, (char) 0xb1, (char) 0xf9,
                    (char) 0xbf),
            new struc((char) 0x62d, (char) 0x9c, (char) 0xb2, (char) 0xfa,
                    (char) 0xc0),
            new struc((char) 0x62e, (char) 0x9d, (char) 0xb3, (char) 0xfe,
                    (char) 0xc1),
            new struc((char) 0x647, (char) 0xac, (char) 0xe4, (char) 0x93,
                    (char) 0xd5),
            new struc((char) 0x639, (char) 0xc9, (char) 0xd3, (char) 0x8b,
                    (char) 0xa4),
            new struc((char) 0x63a, (char) 0xca, (char) 0xdd, (char) 0x8c,
                    (char) 0xa5),
            new struc((char) 0x641, (char) 0xa6, (char) 0xde, (char) 0x8d,
                    (char) 0xcc),
            new struc((char) 0x642, (char) 0xa7, (char) 0xdf, (char) 0x8e,
                    (char) 0xce),
            new struc((char) 0x62b, (char) 0xbd, (char) 0xaf, (char) 0xea,
                    (char) 0x99),
            new struc((char) 0x635, (char) 0xc4, (char) 0xc8, (char) 0x87,
                    (char) 0xa0),
            new struc((char) 0x636, (char) 0xc5, (char) 0xcb, (char) 0x88,
                    (char) 0xa1),
            new struc((char) 0x637, (char) 0xc6, (char) 0xcd, (char) 0xcd,
                    (char) 0xa2),
            new struc((char) 0x643, (char) 0xcf, (char) 0xe0, (char) 0x8f,
                    (char) 0xa8),
            new struc((char) 0x645, (char) 0xd2, (char) 0xe2, (char) 0x91,
                    (char) 0xaa),
            new struc((char) 0x646, (char) 0xd4, (char) 0xe3, (char) 0x92,
                    (char) 0xab),
            new struc((char) 0x62a, (char) 0xbd, (char) 0xaf, (char) 0xea,
                    (char) 0x99),
            new struc((char) 0x627, (char) 0xbb, (char) 0x80, (char) 0xbb,
                    (char) 0x80),
            new struc((char) 0x644, (char) 0xd1, (char) 0xe1, (char) 0x90,
                    (char) 0xa9),
            new struc((char) 0x628, (char) 0xbc, (char) 0xae, (char) 0xe9,
                    (char) 0x98),
            new struc((char) 0x64a, (char) 0xdc, (char) 0xe6, (char) 0x95,
                    (char) 0xdc),
            new struc((char) 0x633, (char) 0xc2, (char) 0xb8, (char) 0xb8,
                    (char) 0x9e),
            new struc((char) 0x634, (char) 0xc3, (char) 0xb9, (char) 0xb9,
                    (char) 0x9f),
            new struc((char) 0x638, (char) 0xc7, (char) 0xcd, (char) 0xcd,
                    (char) 0xc7),
            new struc((char) 0x632, (char) 0xb7, (char) 0xb7, (char) 0xb7,
                    (char) 0xb7),
            new struc((char) 0x648, (char) 0x94, (char) 0x94, (char) 0x94,
                    (char) 0x94),
            new struc((char) 0x629, (char) 0xda, (char) 0xda, (char) 0xda,
                    (char) 0xda),
            new struc((char) 0x649, (char) 0xdc, (char) 0xe6, (char) 0x95,
                    (char) 0xdc),
            new struc((char) 0x631, (char) 0xb6, (char) 0xb6, (char) 0xb6,
                    (char) 0xb6),
            new struc((char) 0x624, (char) 0xe7, (char) 0xe7, (char) 0xe7,
                    (char) 0xe7),
            new struc((char) 0x621, (char) 0xba, (char) 0xba, (char) 0xba,
                    (char) 0xba),
            new struc((char) 0x626, (char) 0xd7, (char) 0xe8, (char) 0x97,
                    (char) 0xd7),
            new struc((char) 0x623, (char) 0x80, (char) 0x80, (char) 0x80,
                    (char) 0x80),
            new struc((char) 0x622, (char) 0x80, (char) 0x80, (char) 0x80,
                    (char) 0x80),
            new struc((char) 0x625, (char) 0x80, (char) 0x80, (char) 0x80,
                    (char) 0x80),
            new struc((char) 0x67e, (char) 0xbc, (char) 0xae, (char) 0xe9,
                    (char) 0x98), // peh
            new struc((char) 0x686, (char) 0x9b, (char) 0xb1, (char) 0xf9,
                    (char) 0xbf), // cheh
            new struc((char) 0x698, (char) 0xb7, (char) 0xb7, (char) 0xb7,
                    (char) 0xb7), // jeh
            new struc((char) 0x6a9, (char) 0xcf, (char) 0xe0, (char) 0x8f,
                    (char) 0xa8), // keheh
            new struc((char) 0x6af, (char) 0xcf, (char) 0xe0, (char) 0x8f,
                    (char) 0xa8), // gaf
            new struc((char) 0x6cc, (char) 0xdc, (char) 0xe6, (char) 0x95,
                    (char) 0xdc), // yeh
            new struc((char) 0x6c0, (char) 0xac, (char) 0xe4, (char) 0x93,
                    (char) 0xd5) // heh with yeh
    };

    private static final int N_DISTINCT_CHARACTERS = 43;

    private static final String ArabicReverse(String s) {
        try {
            String Out = "", rev;
            s = MakeReverse(s);
            char[] chs = new char[s.length()];
            chs = s.toCharArray();
            int i = 0;
            while (i < s.length()) {
                if ((chs[i] >= '0' && chs[i] <= '9')) // isDigit(s[i]) ?
                {
                    rev = "";
                    while (i < s.length()
                            && ((chs[i] >= '0' && chs[i] <= '9') || chs[i] == '/')) // isDigit(s[i])
                                                                                    // ?
                    {
                        rev = rev + chs[i];
                        ++i;
                    }
                    rev = MakeReverse(rev);
                    Out = Out + rev;
                } else {
                    Out = Out + chs[i];
                    ++i;
                }
            }
            s = Out;
        } catch (Exception ex) {
            // throw new Exception(
            // "An exception has occurred in ArabicReverse function.\\n"
            // + ex.getMessage());
        }
        return s;
    }

    private static final boolean isFromTheSet1(/* WCHAR */char ch) {
        char[] theSet1 = new char[] { (char) 0x62c, (char) 0x62d, (char) 0x62e,
                (char) 0x647, (char) 0x639, (char) 0x63a, (char) 0x641,
                (char) 0x642, (char) 0x62b, (char) 0x635, (char) 0x636,
                (char) 0x637, (char) 0x643, (char) 0x645, (char) 0x646,
                (char) 0x62a, (char) 0x644, (char) 0x628, (char) 0x64a,
                (char) 0x633, (char) 0x634, (char) 0x638, (char) 0x67e,
                (char) 0x686, (char) 0x6a9, (char) 0x6af, (char) 0x6cc,
                (char) 0x626 };
        int i = 0;
        while (i < 28) {
            if (ch == theSet1[i])
                return true;
            ++i;
        }
        return false;
    }

    private static final boolean isFromTheSet2(/* WCHAR */char ch) {
        char[] theSet2 = new char[] { (char) 0x627, (char) 0x623, (char) 0x625,
                (char) 0x622, (char) 0x62f, (char) 0x630, (char) 0x631,
                (char) 0x632, (char) 0x648, (char) 0x624, (char) 0x629,
                (char) 0x649, (char) 0x698, (char) 0x6c0 };
        int i = 0;
        while (i < 14) {
            if (ch == theSet2[i])
                return true;
            ++i;
        }
        return false;
    }

    private static final String MakeReverse(String text) {
        String Result = "";
        char[] Ctext = new char[text.length()];
        Ctext = text.toCharArray();
        for (int i = (text.length()) - 1; i >= 0; i--) {
            Result += Ctext[i];
        }
        return Result;
    }

    public static final String ConvertBackToRealFarsi(String In) {

        if (!isFarsiConversionNeeded) {
            return In;
        }

        String strOut = "";
        StringBuilder strBuilder = new StringBuilder("");
        int i = 0;
        int j = 0;
        char[] chIn = new char[In.length()];
        chIn = In.toCharArray();

        for (i = 0; i < In.length(); i++) {
            boolean found = false;
            for (j = 0; j < arrStruc.length; j++) {
                if (chIn[i] == arrStruc[j].midGlyph ||
                        chIn[i] == arrStruc[j].iniGlyph ||
                        chIn[i] == arrStruc[j].endGlyph ||
                        chIn[i] == arrStruc[j].isoGlyph) {
                    strBuilder.append(arrStruc[j].character);
                    found = true;
                    break;
                }
            }
            if (!found)
                strBuilder.append(chIn[i]);
        }

        strOut = strBuilder.toString();
    strOut = strOut.replace(szLa, "");
    strOut = strOut.replace(szLaStick, "");

        return strOut;
    }

    public static final String Convert(String In) {

        if (!isFarsiConversionNeeded) {
            return In;
        }

        if (In == null) {
            return "";
        }

        boolean linkBefore, linkAfter;
        String Out = In;
        char[] chOut = new char[Out.length()];
        chOut = Out.toCharArray();
        char[] chIn = new char[In.length()];
        chIn = In.toCharArray();

        for (int i = 0; i < In.length(); i++) {
            /* WCHAR */
            char ch = chIn[i];
            if ((ch >= (char) 0x0621 && ch <= (char) 0x064a)
                    || (ch == (char) 0x067e) || (ch == (char) 0x0686)
                    || (ch == (char) 0x0698) || (ch == (char) 0x06a9)
                    || (ch == (char) 0x06af) || (ch == (char) 0x06cc)
                    || (ch == (char) 0x06c0)) // is a Farsi character?
            {
                int idx = 0;
                while (idx < N_DISTINCT_CHARACTERS) {
                    if (arrStruc[idx].character == chIn[i])
                        break;
                    ++idx;
                }

                if (i == In.length() - 1)
                    linkAfter = false;
                else
                    linkAfter = (isFromTheSet1(chIn[i + 1]) || isFromTheSet2(chIn[i + 1]));
                if (i == 0)
                    linkBefore = false;
                else
                    linkBefore = isFromTheSet1(chIn[i - 1]);
                if (idx < N_DISTINCT_CHARACTERS) {
                    if (linkBefore && linkAfter)
                        chOut[i] = arrStruc[idx].midGlyph;
                    if (linkBefore && !linkAfter)
                        chOut[i] = arrStruc[idx].endGlyph;
                    if (!linkBefore && linkAfter)
                        chOut[i] = arrStruc[idx].iniGlyph;
                    if (!linkBefore && !linkAfter)
                        chOut[i] = arrStruc[idx].isoGlyph;
                } else {
                    chOut[i] = chIn[i];
                }
            } else {
                chOut[i] = chIn[i];
            }
        }
        Out = "";
        for (int j = 0; j < chOut.length; j++)
            Out += chOut[j];
        // Out = ArabicReverse(Out);

        Out = Out.replace((char) 0x200c, ' '); // Change NO SPACE to SPACE

        Out = Out.replace(szLamAndAlef, szLa); // Join 'Lam' and 'Alef' and
                                                // make 'La'
        Out = Out.replace(szLamStickAndAlef, szLaStick); // Join 'Lam Stick'
                                                            // and 'Alef'
                                                            // and make 'La
                                                            // Stick'

        return reorderWords(Out);

    }

    private final static String reorderWords(String strIn)
    {

        final int ST_RTL = 0;
        final int ST_LTR = 1;

        String strOut = "";
        String prevWord = "";
        int state = ST_RTL;
        char[] arr = strIn.toCharArray();
        int i = 0;
        while (i < arr.length) {
            if (charIsLTR(arr[i]) && state != ST_LTR)
            {
                // state changed to LTR
                state = ST_LTR;
                strOut = prevWord + strOut;
                prevWord = "";
                prevWord += arr[i];
            }
            else if (charIsRTL(arr[i]) && state != ST_RTL)
            {
                // state changed to RTL
                state = ST_RTL;
                strOut = prevWord + strOut;
                prevWord = "";
                prevWord += arr[i];
            }
            else
            {
                // state is not changed
                prevWord += arr[i];
            }
            i++;
        }

        strOut = prevWord + strOut;

        return strOut;

    }

    private final static boolean charIsLTR(char ch)
    {
        return (ch >= (char) 65 & ch <= (char) 122)
                |
                Character.isDigit(ch);
    }

    private final static boolean charIsRTL(char ch)
    {
        return ch >= (char) 0x0621;
    }   

    private static Typeface typeface;

    public static final Typeface GetFarsiFont(Context context) {
        if (typeface == null) {
            typeface = Typeface.createFromAsset(context.getAssets(),
                    // "DroidSansFallback.ttf");
                    "TAHOMA.TTF");
        }
        return typeface;
    }
}

3) And in your Activity:

Typeface tf = Farsi.GetFarsiFont(this);
MyTextView.setTypeface(tf);
MyTextView.setText(Farsi.Convert(""));

please do not add lots of "follow this link" posts as answers on other questions; a link by itself is not really an answer. I have converted them to comments, so they will still show as related, but without the need for empty answers.

@totti roma: you are getting Exception Because "tahoma.ttf" Written In Caps in that Code and Your File name mighrt not be in caps. Change this and try again

Thanks a lot, it saves a lot of time while I am searching for ROM with Arabic support

@breceivemail .. I was having an exception when I have more than two TextView in one Layout. I used another library and solved the problem github.com/agawish/Better-Arabic-Reshaper/commits/master

@Tina Yes I think it is a bug. I have asked about it in this link: stackoverflow.com/q/7426266/779408

internationalization - How to support Arabic text in Android? - Stack ...

android internationalization arabic persian farsi
Rectangle 27 134

Android 2.1 does not have Arabic font.

Android 2.2 has Arabic font but does not show your word correctly.

Farsi.GetFarsiFont(this)
Farsi.Convert("")

For Android 2.2 you do not need setting font but must use Farsi.Convert("")

And for Android 3.x forget all of the above solutions ;). But you can change the font if you do not like the 3.x Arabic font.

so do the following steps:

2) use the following class to get the font and converting your Arabic or Farsi text to a good form for showing in your activities.

import android.content.Context;
import android.graphics.Typeface;

public final class Farsi {

    public static boolean isFarsiConversionNeeded = true;

    private final static String szLamAndAlef = Character
            .toString((char) 0xfedf)
            + Character.toString((char) 0xfe8e); // Lam + Alef

    private final static String szLamStickAndAlef = Character
            .toString((char) 0xfee0)
            + Character.toString((char) 0xfe8e); // Lam (Sticky !!!)+
                                                    // Alef

    private final static String szLa = Character.toString((char) 0xfefb); // La
    private final static String szLaStick = Character.toString((char) 0xfefc); // La
                                                                                // (Sticky!!!)

    private final static String szLamAndAlefWoosim = Character
            .toString((char) 0xe1)
            + Character.toString((char) 0xbb); // Lam + Alef

    private final static String szLamStickAndAlefWoosim = Character
            .toString((char) 0x90)
            + Character.toString((char) 0xbb); // Lam (Sticky !!!)+
                                                // Alef

    private final static String szLaWoosim = Character.toString((char) 0xd9); // La
    private final static String szLaStickWoosim = Character
            .toString((char) 0xd9); // La

    // (Sticky!!!)

    private static final class struc {
        public char character;
        public char endGlyph;
        public char iniGlyph;
        public char midGlyph;
        public char isoGlyph;

        public struc(char Character, char EndGlyph, char IniGlyph,
                char MidGlyph, char IsoGlyph) {
            character = Character;
            endGlyph = EndGlyph;
            iniGlyph = IniGlyph;
            midGlyph = MidGlyph;
            isoGlyph = IsoGlyph;
        }
    }

    static struc[] arrStruc = {
            new struc((char) 0x630, (char) 0xfeac, (char) 0xfeab,
                    (char) 0xfeac, (char) 0xfeab),
            new struc((char) 0x62f, (char) 0xfeaa, (char) 0xfea9,
                    (char) 0xfeaa, (char) 0xfea9),
            new struc((char) 0x62c, (char) 0xfe9e, (char) 0xfe9f,
                    (char) 0xfea0, (char) 0xfe9d),
            new struc((char) 0x62d, (char) 0xfea2, (char) 0xfea3,
                    (char) 0xfea4, (char) 0xfea1),
            new struc((char) 0x62e, (char) 0xfea6, (char) 0xfea7,
                    (char) 0xfea8, (char) 0xfea5),
            new struc((char) 0x647, (char) 0xfeea, (char) 0xfeeb,
                    (char) 0xfeec, (char) 0xfee9),
            new struc((char) 0x639, (char) 0xfeca, (char) 0xfecb,
                    (char) 0xfecc, (char) 0xfec9),
            new struc((char) 0x63a, (char) 0xfece, (char) 0xfecf,
                    (char) 0xfed0, (char) 0xfecd),
            new struc((char) 0x641, (char) 0xfed2, (char) 0xfed3,
                    (char) 0xfed4, (char) 0xfed1),
            new struc((char) 0x642, (char) 0xfed6, (char) 0xfed7,
                    (char) 0xfed8, (char) 0xfed5),
            new struc((char) 0x62b, (char) 0xfe9a, (char) 0xfe9b,
                    (char) 0xfe9c, (char) 0xfe99),
            new struc((char) 0x635, (char) 0xfeba, (char) 0xfebb,
                    (char) 0xfebc, (char) 0xfeb9),
            new struc((char) 0x636, (char) 0xfebe, (char) 0xfebf,
                    (char) 0xfec0, (char) 0xfebd),
            new struc((char) 0x637, (char) 0xfec2, (char) 0xfec3,
                    (char) 0xfec4, (char) 0xfec1),
            new struc((char) 0x643, (char) 0xfeda, (char) 0xfedb,
                    (char) 0xfedc, (char) 0xfed9),
            new struc((char) 0x645, (char) 0xfee2, (char) 0xfee3,
                    (char) 0xfee4, (char) 0xfee1),
            new struc((char) 0x646, (char) 0xfee6, (char) 0xfee7,
                    (char) 0xfee8, (char) 0xfee5),
            new struc((char) 0x62a, (char) 0xfe96, (char) 0xfe97,
                    (char) 0xfe98, (char) 0xfe95),
            new struc((char) 0x627, (char) 0xfe8e, (char) 0xfe8d,
                    (char) 0xfe8e, (char) 0xfe8d),
            new struc((char) 0x644, (char) 0xfede, (char) 0xfedf,
                    (char) 0xfee0, (char) 0xfedd),
            new struc((char) 0x628, (char) 0xfe90, (char) 0xfe91,
                    (char) 0xfe92, (char) 0xfe8f),
            new struc((char) 0x64a, (char) 0xfef2, (char) 0xfef3,
                    (char) 0xfef4, (char) 0xfef1),
            new struc((char) 0x633, (char) 0xfeb2, (char) 0xfeb3,
                    (char) 0xfeb4, (char) 0xfeb1),
            new struc((char) 0x634, (char) 0xfeb6, (char) 0xfeb7,
                    (char) 0xfeb8, (char) 0xfeb5),
            new struc((char) 0x638, (char) 0xfec6, (char) 0xfec7,
                    (char) 0xfec8, (char) 0xfec5),
            new struc((char) 0x632, (char) 0xfeb0, (char) 0xfeaf,
                    (char) 0xfeb0, (char) 0xfeaf),
            new struc((char) 0x648, (char) 0xfeee, (char) 0xfeed,
                    (char) 0xfeee, (char) 0xfeed),
            new struc((char) 0x629, (char) 0xfe94, (char) 0xfe93,
                    (char) 0xfe93, (char) 0xfe93),
            new struc((char) 0x649, (char) 0xfef0, (char) 0xfeef,
                    (char) 0xfef0, (char) 0xfeef),
            new struc((char) 0x631, (char) 0xfeae, (char) 0xfead,
                    (char) 0xfeae, (char) 0xfead),
            new struc((char) 0x624, (char) 0xfe86, (char) 0xfe85,
                    (char) 0xfe86, (char) 0xfe85),
            new struc((char) 0x621, (char) 0xfe80, (char) 0xfe80,
                    (char) 0xfe80, (char) 0xfe80),
            new struc((char) 0x626, (char) 0xfe8a, (char) 0xfe8b,
                    (char) 0xfe8c, (char) 0xfe89),
            new struc((char) 0x623, (char) 0xfe84, (char) 0xfe83,
                    (char) 0xfe84, (char) 0xfe83),
            new struc((char) 0x622, (char) 0xfe82, (char) 0xfe81,
                    (char) 0xfe82, (char) 0xfe81),
            new struc((char) 0x625, (char) 0xfe88, (char) 0xfe87,
                    (char) 0xfe88, (char) 0xfe87),
            new struc((char) 0x67e, (char) 0xfb57, (char) 0xfb58,
                    (char) 0xfb59, (char) 0xfb56), // peh
            new struc((char) 0x686, (char) 0xfb7b, (char) 0xfb7c,
                    (char) 0xfb7d, (char) 0xfb7a), // cheh
            new struc((char) 0x698, (char) 0xfb8b, (char) 0xfb8a,
                    (char) 0xfb8b, (char) 0xfb8a), // jeh
            new struc((char) 0x6a9, (char) 0xfb8f, (char) 0xfb90,
                    (char) 0xfb91, (char) 0xfb8e), // keheh
            new struc((char) 0x6af, (char) 0xfb93, (char) 0xfb94,
                    (char) 0xfb95, (char) 0xfb92), // gaf
            // new struc((char) 0x6cc, (char) 0xfbfd, (char) 0xfbfe,
            // (char) 0xfbff, (char) 0xfbfc), // Farsi yeh
            new struc((char) 0x6cc, (char) 0xfbfd, (char) 0xfef3,
                    (char) 0xfef4, (char) 0xfbfc), // Arabic yeh
            new struc((char) 0x6c0, (char) 0xfba5, (char) 0xfba4,
                    (char) 0xfba5, (char) 0xfba4) // heh with yeh
    };

    static struc[] arrStrucWoosim = {
            new struc((char) 0x630, (char) 0xb5, (char) 0x82, (char) 0xb5,
                    (char) 0x82),
            new struc((char) 0x62f, (char) 0xb4, (char) 0x81, (char) 0xb4,
                    (char) 0x81),
            new struc((char) 0x62c, (char) 0x9b, (char) 0xb1, (char) 0xf9,
                    (char) 0xbf),
            new struc((char) 0x62d, (char) 0x9c, (char) 0xb2, (char) 0xfa,
                    (char) 0xc0),
            new struc((char) 0x62e, (char) 0x9d, (char) 0xb3, (char) 0xfe,
                    (char) 0xc1),
            new struc((char) 0x647, (char) 0xac, (char) 0xe4, (char) 0x93,
                    (char) 0xd5),
            new struc((char) 0x639, (char) 0xc9, (char) 0xd3, (char) 0x8b,
                    (char) 0xa4),
            new struc((char) 0x63a, (char) 0xca, (char) 0xdd, (char) 0x8c,
                    (char) 0xa5),
            new struc((char) 0x641, (char) 0xa6, (char) 0xde, (char) 0x8d,
                    (char) 0xcc),
            new struc((char) 0x642, (char) 0xa7, (char) 0xdf, (char) 0x8e,
                    (char) 0xce),
            new struc((char) 0x62b, (char) 0xbd, (char) 0xaf, (char) 0xea,
                    (char) 0x99),
            new struc((char) 0x635, (char) 0xc4, (char) 0xc8, (char) 0x87,
                    (char) 0xa0),
            new struc((char) 0x636, (char) 0xc5, (char) 0xcb, (char) 0x88,
                    (char) 0xa1),
            new struc((char) 0x637, (char) 0xc6, (char) 0xcd, (char) 0xcd,
                    (char) 0xa2),
            new struc((char) 0x643, (char) 0xcf, (char) 0xe0, (char) 0x8f,
                    (char) 0xa8),
            new struc((char) 0x645, (char) 0xd2, (char) 0xe2, (char) 0x91,
                    (char) 0xaa),
            new struc((char) 0x646, (char) 0xd4, (char) 0xe3, (char) 0x92,
                    (char) 0xab),
            new struc((char) 0x62a, (char) 0xbd, (char) 0xaf, (char) 0xea,
                    (char) 0x99),
            new struc((char) 0x627, (char) 0xbb, (char) 0x80, (char) 0xbb,
                    (char) 0x80),
            new struc((char) 0x644, (char) 0xd1, (char) 0xe1, (char) 0x90,
                    (char) 0xa9),
            new struc((char) 0x628, (char) 0xbc, (char) 0xae, (char) 0xe9,
                    (char) 0x98),
            new struc((char) 0x64a, (char) 0xdc, (char) 0xe6, (char) 0x95,
                    (char) 0xdc),
            new struc((char) 0x633, (char) 0xc2, (char) 0xb8, (char) 0xb8,
                    (char) 0x9e),
            new struc((char) 0x634, (char) 0xc3, (char) 0xb9, (char) 0xb9,
                    (char) 0x9f),
            new struc((char) 0x638, (char) 0xc7, (char) 0xcd, (char) 0xcd,
                    (char) 0xc7),
            new struc((char) 0x632, (char) 0xb7, (char) 0xb7, (char) 0xb7,
                    (char) 0xb7),
            new struc((char) 0x648, (char) 0x94, (char) 0x94, (char) 0x94,
                    (char) 0x94),
            new struc((char) 0x629, (char) 0xda, (char) 0xda, (char) 0xda,
                    (char) 0xda),
            new struc((char) 0x649, (char) 0xdc, (char) 0xe6, (char) 0x95,
                    (char) 0xdc),
            new struc((char) 0x631, (char) 0xb6, (char) 0xb6, (char) 0xb6,
                    (char) 0xb6),
            new struc((char) 0x624, (char) 0xe7, (char) 0xe7, (char) 0xe7,
                    (char) 0xe7),
            new struc((char) 0x621, (char) 0xba, (char) 0xba, (char) 0xba,
                    (char) 0xba),
            new struc((char) 0x626, (char) 0xd7, (char) 0xe8, (char) 0x97,
                    (char) 0xd7),
            new struc((char) 0x623, (char) 0x80, (char) 0x80, (char) 0x80,
                    (char) 0x80),
            new struc((char) 0x622, (char) 0x80, (char) 0x80, (char) 0x80,
                    (char) 0x80),
            new struc((char) 0x625, (char) 0x80, (char) 0x80, (char) 0x80,
                    (char) 0x80),
            new struc((char) 0x67e, (char) 0xbc, (char) 0xae, (char) 0xe9,
                    (char) 0x98), // peh
            new struc((char) 0x686, (char) 0x9b, (char) 0xb1, (char) 0xf9,
                    (char) 0xbf), // cheh
            new struc((char) 0x698, (char) 0xb7, (char) 0xb7, (char) 0xb7,
                    (char) 0xb7), // jeh
            new struc((char) 0x6a9, (char) 0xcf, (char) 0xe0, (char) 0x8f,
                    (char) 0xa8), // keheh
            new struc((char) 0x6af, (char) 0xcf, (char) 0xe0, (char) 0x8f,
                    (char) 0xa8), // gaf
            new struc((char) 0x6cc, (char) 0xdc, (char) 0xe6, (char) 0x95,
                    (char) 0xdc), // yeh
            new struc((char) 0x6c0, (char) 0xac, (char) 0xe4, (char) 0x93,
                    (char) 0xd5) // heh with yeh
    };

    private static final int N_DISTINCT_CHARACTERS = 43;

    private static final String ArabicReverse(String s) {
        try {
            String Out = "", rev;
            s = MakeReverse(s);
            char[] chs = new char[s.length()];
            chs = s.toCharArray();
            int i = 0;
            while (i < s.length()) {
                if ((chs[i] >= '0' && chs[i] <= '9')) // isDigit(s[i]) ?
                {
                    rev = "";
                    while (i < s.length()
                            && ((chs[i] >= '0' && chs[i] <= '9') || chs[i] == '/')) // isDigit(s[i])
                                                                                    // ?
                    {
                        rev = rev + chs[i];
                        ++i;
                    }
                    rev = MakeReverse(rev);
                    Out = Out + rev;
                } else {
                    Out = Out + chs[i];
                    ++i;
                }
            }
            s = Out;
        } catch (Exception ex) {
            // throw new Exception(
            // "An exception has occurred in ArabicReverse function.\\n"
            // + ex.getMessage());
        }
        return s;
    }

    private static final boolean isFromTheSet1(/* WCHAR */char ch) {
        char[] theSet1 = new char[] { (char) 0x62c, (char) 0x62d, (char) 0x62e,
                (char) 0x647, (char) 0x639, (char) 0x63a, (char) 0x641,
                (char) 0x642, (char) 0x62b, (char) 0x635, (char) 0x636,
                (char) 0x637, (char) 0x643, (char) 0x645, (char) 0x646,
                (char) 0x62a, (char) 0x644, (char) 0x628, (char) 0x64a,
                (char) 0x633, (char) 0x634, (char) 0x638, (char) 0x67e,
                (char) 0x686, (char) 0x6a9, (char) 0x6af, (char) 0x6cc,
                (char) 0x626 };
        int i = 0;
        while (i < 28) {
            if (ch == theSet1[i])
                return true;
            ++i;
        }
        return false;
    }

    private static final boolean isFromTheSet2(/* WCHAR */char ch) {
        char[] theSet2 = new char[] { (char) 0x627, (char) 0x623, (char) 0x625,
                (char) 0x622, (char) 0x62f, (char) 0x630, (char) 0x631,
                (char) 0x632, (char) 0x648, (char) 0x624, (char) 0x629,
                (char) 0x649, (char) 0x698, (char) 0x6c0 };
        int i = 0;
        while (i < 14) {
            if (ch == theSet2[i])
                return true;
            ++i;
        }
        return false;
    }

    private static final String MakeReverse(String text) {
        String Result = "";
        char[] Ctext = new char[text.length()];
        Ctext = text.toCharArray();
        for (int i = (text.length()) - 1; i >= 0; i--) {
            Result += Ctext[i];
        }
        return Result;
    }

    public static final String ConvertBackToRealFarsi(String In) {

        if (!isFarsiConversionNeeded) {
            return In;
        }

        String strOut = "";
        StringBuilder strBuilder = new StringBuilder("");
        int i = 0;
        int j = 0;
        char[] chIn = new char[In.length()];
        chIn = In.toCharArray();

        for (i = 0; i < In.length(); i++) {
            boolean found = false;
            for (j = 0; j < arrStruc.length; j++) {
                if (chIn[i] == arrStruc[j].midGlyph ||
                        chIn[i] == arrStruc[j].iniGlyph ||
                        chIn[i] == arrStruc[j].endGlyph ||
                        chIn[i] == arrStruc[j].isoGlyph) {
                    strBuilder.append(arrStruc[j].character);
                    found = true;
                    break;
                }
            }
            if (!found)
                strBuilder.append(chIn[i]);
        }

        strOut = strBuilder.toString();
    strOut = strOut.replace(szLa, "");
    strOut = strOut.replace(szLaStick, "");

        return strOut;
    }

    public static final String Convert(String In) {

        if (!isFarsiConversionNeeded) {
            return In;
        }

        if (In == null) {
            return "";
        }

        boolean linkBefore, linkAfter;
        String Out = In;
        char[] chOut = new char[Out.length()];
        chOut = Out.toCharArray();
        char[] chIn = new char[In.length()];
        chIn = In.toCharArray();

        for (int i = 0; i < In.length(); i++) {
            /* WCHAR */
            char ch = chIn[i];
            if ((ch >= (char) 0x0621 && ch <= (char) 0x064a)
                    || (ch == (char) 0x067e) || (ch == (char) 0x0686)
                    || (ch == (char) 0x0698) || (ch == (char) 0x06a9)
                    || (ch == (char) 0x06af) || (ch == (char) 0x06cc)
                    || (ch == (char) 0x06c0)) // is a Farsi character?
            {
                int idx = 0;
                while (idx < N_DISTINCT_CHARACTERS) {
                    if (arrStruc[idx].character == chIn[i])
                        break;
                    ++idx;
                }

                if (i == In.length() - 1)
                    linkAfter = false;
                else
                    linkAfter = (isFromTheSet1(chIn[i + 1]) || isFromTheSet2(chIn[i + 1]));
                if (i == 0)
                    linkBefore = false;
                else
                    linkBefore = isFromTheSet1(chIn[i - 1]);
                if (idx < N_DISTINCT_CHARACTERS) {
                    if (linkBefore && linkAfter)
                        chOut[i] = arrStruc[idx].midGlyph;
                    if (linkBefore && !linkAfter)
                        chOut[i] = arrStruc[idx].endGlyph;
                    if (!linkBefore && linkAfter)
                        chOut[i] = arrStruc[idx].iniGlyph;
                    if (!linkBefore && !linkAfter)
                        chOut[i] = arrStruc[idx].isoGlyph;
                } else {
                    chOut[i] = chIn[i];
                }
            } else {
                chOut[i] = chIn[i];
            }
        }
        Out = "";
        for (int j = 0; j < chOut.length; j++)
            Out += chOut[j];
        // Out = ArabicReverse(Out);

        Out = Out.replace((char) 0x200c, ' '); // Change NO SPACE to SPACE

        Out = Out.replace(szLamAndAlef, szLa); // Join 'Lam' and 'Alef' and
                                                // make 'La'
        Out = Out.replace(szLamStickAndAlef, szLaStick); // Join 'Lam Stick'
                                                            // and 'Alef'
                                                            // and make 'La
                                                            // Stick'

        return reorderWords(Out);

    }

    private final static String reorderWords(String strIn)
    {

        final int ST_RTL = 0;
        final int ST_LTR = 1;

        String strOut = "";
        String prevWord = "";
        int state = ST_RTL;
        char[] arr = strIn.toCharArray();
        int i = 0;
        while (i < arr.length) {
            if (charIsLTR(arr[i]) && state != ST_LTR)
            {
                // state changed to LTR
                state = ST_LTR;
                strOut = prevWord + strOut;
                prevWord = "";
                prevWord += arr[i];
            }
            else if (charIsRTL(arr[i]) && state != ST_RTL)
            {
                // state changed to RTL
                state = ST_RTL;
                strOut = prevWord + strOut;
                prevWord = "";
                prevWord += arr[i];
            }
            else
            {
                // state is not changed
                prevWord += arr[i];
            }
            i++;
        }

        strOut = prevWord + strOut;

        return strOut;

    }

    private final static boolean charIsLTR(char ch)
    {
        return (ch >= (char) 65 & ch <= (char) 122)
                |
                Character.isDigit(ch);
    }

    private final static boolean charIsRTL(char ch)
    {
        return ch >= (char) 0x0621;
    }   

    private static Typeface typeface;

    public static final Typeface GetFarsiFont(Context context) {
        if (typeface == null) {
            typeface = Typeface.createFromAsset(context.getAssets(),
                    // "DroidSansFallback.ttf");
                    "TAHOMA.TTF");
        }
        return typeface;
    }
}

3) And in your Activity:

Typeface tf = Farsi.GetFarsiFont(this);
MyTextView.setTypeface(tf);
MyTextView.setText(Farsi.Convert(""));

please do not add lots of "follow this link" posts as answers on other questions; a link by itself is not really an answer. I have converted them to comments, so they will still show as related, but without the need for empty answers.

@totti roma: you are getting Exception Because "tahoma.ttf" Written In Caps in that Code and Your File name mighrt not be in caps. Change this and try again

Thanks a lot, it saves a lot of time while I am searching for ROM with Arabic support

@breceivemail .. I was having an exception when I have more than two TextView in one Layout. I used another library and solved the problem github.com/agawish/Better-Arabic-Reshaper/commits/master

@Tina Yes I think it is a bug. I have asked about it in this link: stackoverflow.com/q/7426266/779408

internationalization - How to support Arabic text in Android? - Stack ...

android internationalization arabic persian farsi
Rectangle 27 2

If you are using I18n::Fallbacks unfortunately you can't use I18n.t('.') as it just returns the contents current locale (eg. 'en-GB') and nothing from any of the fallback locales (eg 'en'). To get round this you can iterate over the fallbacks and use deep_merge! to combine them.

module I18n
  class << self
    def all
      fallbacks[I18n.locale].reverse.reduce({}) do |translations, fallback|
        translations.deep_merge!(backend.translate(fallback, '.'))
      end
    end
  end
end

internationalization - How to retrieve all translations from yml files...

ruby-on-rails internationalization yaml rails-i18n