Nile::Lang - Language file manager.
$lang = $self->me->lang; # load language file from the current active or default language, file extension is xml. $lang->load("general"); # load and append another language file $lang->load("accounts"); # load language file of specific language. $lang->load($file, $lang); # get language variables from the active langauge say $lang->get("site_name"); say $lang->get("first_name"); say $lang->get("last_name"); # get language variables of specific installed language. say $lang->get("site_name", 'en-US'); # automatic getter support say $lang->email; # same as $lang->get('email'); # get a group of language variables. @text = $lang->list(@names); # set language variables. $lang->set("email_label", 'Email:'); $lang->set(%vars); # automatic setter support $lang->email('ahmed@mewsoft.com'); # same as $lang->set('email', 'ahmed@mewsoft.com');
# set output file name for saving $lang->file($file); # get output file name $file = $lang->file();
Get and set the output language file name used when saving or updating. The default file extension is xml.
# get encoding used to read/write the language files, default is 'UTF-8'. $encoding = $lang->encoding(); # set encoding used to read/write the langauge files, default is 'UTF-8'. $lang->encoding('UTF-8');
Get and set encoding used to read/write the language files. The default encoding is 'UTF-8'.
# load language file from the current active or default language, file extension is xml. $lang->load("general"); # load and append another language file $lang->load("accounts"); # load language file of specific language. $lang->load($file, $lang);
Load language files from the current active or specific language. The default file extension is xml. This method can be chained $lang-load($file)->load($register)>;
$lang-
# load a list of language files from the current active or default language, file extension is xml. $lang->add("general", "register", "contact");
Load a list of language files from the current active or specific language. The default file extension is xml. This method can be chained $lang-load($file, $lang)->add(@files)>;
# reload a list of language files from the current active or default language, file extension is xml. $lang->reload("general", "register");
Reload a list of language files from the current active or specific language. The default file extension is xml. This method can be chained.
# get active language for the language object. $lang = $lang->lang(); # set active language for the language object. $lang->lang("en-US");
Get and set active language used when loading or writing the language files.
# clear all loaded language data. $lang = $lang->clear(); # clear all loaded language data of sepcific language. $lang->clear("en-US");
Clear all loaded language data or sepcific language or all languages. This does not delete the data from files.
# get all loaded language data as hash or hash ref. %data = $lang->vars(); $data_ref = $lang->vars(); # get all loaded language data of sepcific language as hash or hash ref. %data = $lang->vars("en-US"); $data_ref = $lang->vars("en-US");
Returns all loaded language data as a hash or hash reference of sepcific language or all languages.
# get language variables from the active langauge say $lang->get("site_name"); say $lang->get("first_name"); say $lang->get("last_name"); # get language variables of specific installed language. say $lang->get("site_name", 'en-US'); # automatic getter support say $lang->email; # same as $lang->get('email');
Returns language variables from the active or specific installed language.
# set language variables. $lang->set("email_label", 'Email:'); $lang->set(%vars); # automatic setter support $lang->email('ahmed@mewsoft.com'); # same as $lang->set('email', 'ahmed@mewsoft.com');
Set language variables of the active language.
# get a list of language variables. @text = $lang->list(@names);
Set a list of language variables from the active language.
# returns all language variables names. @names = $lang->keys($);
Returns all language variables names.
# check if a langugage variable exist or not. $found = $lang->exists($name);
Check if a langugage variable exist or not.
# delete langugage variables. $lang->delete(@names);
Delete a list of language variables.
# returns language file data from the active or default language, default file extension is xml. %data = $lang->get_file("contacts"); $data_ref = $lang->get_file("contacts"); # returns language file data from specific language, default file extension is xml. %data = $lang->get_file("contacts", "en-US"); $data_ref = $lang->get_file("contacts", "en-US");
Returns language file data as a hash or hash reference from the active or specific language. The default file extension is xml.
# write the output file. $lang->save($file);
Save changes to the output file. If no file name it will update the loaded file name.
# scan and replace the language variables $passes times in language $lang $content = $lang->translate($content, $lang, $passes) # pass content by ref for better speed $lang->translate(\$content, $lang, $passes) # use current language and default passes $content = $lang->translate($content); $lang->translate(\$content); # use specific language and passes $lang->translate($content, "en-US", 3);
Translate language variables inside contents to their language values. It scans the content for the langauge variables surrounded by the curly braces {var_name} and replaces them with their values from the loaded language files.
$content = $lang->translate_file($file, $lang, $passes); # use current langauge and default passes $content = $lang->translate_file($file); $content = $lang->translate_file($file, $lang);
Loads and translates a file. The $file argument must be the full system file path.
# get a new lang object #my $lang_ar = $lang->object; # load and manage a language files separately #$lang_ar->load("general", "ar");
Returns a new language object. This allows to load individual language files and work with them.
This project is available on github at https://github.com/mewsoft/Nile.
Please visit the project's homepage at https://metacpan.org/release/Nile.
Source repository is at https://github.com/mewsoft/Nile.
See Nile for details about the complete framework.
Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Nile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nile
CPAN shell
perl -MCPAN -e shell install Nile
For more information on module installation, please visit the detailed CPAN module installation guide.