Locale::Country::Multilingual - ISO codes for country identification with multi-language (ISO 3166)


    use Locale::Country::Multilingual;

    my $lcm = Locale::Country::Multilingual->new();
    $country = $lcm->code2country('jp');        # $country gets 'Japan'
    $country = $lcm->code2country('chn');       # $country gets 'China'
    $country = $lcm->code2country('250');       # $country gets 'France'
    $code    = $lcm->country2code('Norway');    # $code gets 'no'
    $lcm->set_lang('cn'); # set default language to Chinese
    $country = $lcm->code2country('cn');        # $country gets '中国'
    $code    = $lcm->country2code('日本');      # $code gets 'jp'
    @codes   = $lcm->all_country_codes();
    @names   = $lcm->all_country_names();
    # more heavy call
    my $lang = 'en';
    $country = $lcm->code2country('cn', $lang);        # $country gets 'China'
    $lang = 'cn';
    $country = $lcm->code2country('cn', $lang);        # $country gets '中国'
    my $CODE = 'LOCALE_CODE_ALPHA_2'; # by default
    $code    = $lcm->country2code('Norway', $CODE);    # $code gets 'no'
    $code    = $lcm->country2code('Norway', $CODE);    # $code gets 'nor'
    $code    = $lcm->country2code('Norway', $CODE);    # $code gets '578'
    $code    = $lcm->country2code('挪威', $CODE, 'cn');    # with lang=cn
    $lang = 'cn';
    @codes   = $lcm->all_country_codes($CODE);         # return codes with 3alpha
    @names   = $lcm->all_country_names($lang);         # get all Chinese Countries Names



  use Locale::Country::Multilingual 'en', 'fr', {use_io_layer => 1};

The import class method is called when a module is use'd. Language files can be pre-loaded at compile time, by specifying their two-letter ISO codes. This can be useful when several processes are forked from the main application, e.g. in an Apache mod_perl environment - language data that is loaded before forking, is shared by all processes.

The last argument can be a reference to a hash of options.

The only option ATM is use_io_layer. See Locale::Country::Multilingual::Unicode for more information.


  $lcm = Locale::Country::Multilingual->new;
  $lcm = Locale::Country::Multilingual->new(
    lang => 'es',
    use_io_layer => 1,

Constructor method. Accepts optional list of named arguments:


The language to use. See "AVAILABLE LANGAUGES" for what codes are accepted.


Set this true if you need correct encoding behavior. See Locale::Country::Multilingual::Unicode for more information.



Set the current language. Only argument is a two-letter ISO code.

See "AVAILABLE LANGAUGES" for what codes are accepted.

This method does not actually load the language data. Use "assert_lang" if you really need to know for sure if a language is supported.


  $lang = $lcm->assert_lang('es', 'it', 'fr');

Tries to load any of the given languages. Returns the language code for the first language that was successfully loaded. Returns undef if none of the given languages could be loaded. Actually loads the language data, but does not set the language, so you probably want to use it this way:

  $lang = $lcm->assert_lang(qw/es it fr en/)
    and $lcm->set_lang($lang)
    or die "unable to load any language\n";


  $country = $lcm->code2country('gb');
  $country = $lcm->code2country('gb', 'cn');

Turns an ISO 3166-1 code into a country name in the current language. The default language is "en".

Accepts either two-letter or a three-letter code or a 3 digit numerical code.

A language might be given as second argument to set the output language only for this call - it does not change the current language, that was set with "set_lang".

Returns the country name.

This method croaks if the language is not available.


  $code = $lcm->country2code(
    'République tchèque', 'LOCALE_CODE_ALPHA_2', 'fr'

Take a country name and return the two-letter code when available. Aside from being case-insensitive the country must be written exactly the way how "code2country" returns it.

The second argument is optional and can be one of "LOCALE_CODE_ALPHA_2", "LOCALE_CODE_ALPHA_3" and "LOCALE_CODE_NUMERIC". The default is "LOCALE_CODE_ALPHA2".

The third argument is the language to use for the country name and is optional too.

Returns an ISO-3166 code or undef if search fails.

This method croaks if the language is not available.



  @countrynames = $lcm->all_country_names;
  @countrynames = $lcm->all_country_names('fr');

Returns an array of all lowercased country names in the current or given locale.


en - English
cn - Chinese Simp.
tw - Chinese Trad.
it - Italian
es - Spanish
pt - Portuguese
de - German
fr - French
ja - Japanese
no - Norwegian

other languages are welcome to send by email.




Thanks to michele ongaro for Italian/Spanish/Portuguese/German/French/Japanese dat files.

Thanks to Andreas Marienborg for Norwegian dat file.


Fayland Lam, <fayland at>


Copyright 2007-2008 Fayland Lam, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 179:

Non-ASCII character seen before =encoding in ''中国''. Assuming UTF-8