blob: a148d5a0d3800f14db04ab72688d522671ff1fab [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001##############
2Language Class
3##############
4
5The Language Class provides functions to retrieve language files and
6lines of text for purposes of internationalization.
7
8In your CodeIgniter system folder you'll find one called language
9containing sets of language files. You can create your own language
10files as needed in order to display error and other messages in other
11languages.
12
13Language files are typically stored in your system/language directory.
14Alternately you can create a folder called language inside your
15application folder and store them there. CodeIgniter will look first in
16your application/language directory. If the directory does not exist or
17the specified language is not located there CI will instead look in your
18global system/language folder.
19
20.. note:: Each language should be stored in its own folder. For example,
21 the English files are located at: system/language/english
22
23Creating Language Files
24=======================
25
26Language files must be named with _lang.php as the file extension. For
27example, let's say you want to create a file containing error messages.
28You might name it: error_lang.php
29
30Within the file you will assign each line of text to an array called
31$lang with this prototype::
32
33 $lang['language_key'] = "The actual message to be shown";
34
35.. note:: It's a good practice to use a common prefix for all messages
36 in a given file to avoid collisions with similarly named items in other
37 files. For example, if you are creating error messages you might prefix
38 them with error\_
39
40::
41
42 $lang['error_email_missing'] = "You must submit an email address"; $lang['error_url_missing'] = "You must submit a URL"; $lang['error_username_missing'] = "You must submit a username";
43
44Loading A Language File
45=======================
46
47In order to fetch a line from a particular file you must load the file
48first. Loading a language file is done with the following code::
49
50 $this->lang->load('filename', 'language');
51
52Where filename is the name of the file you wish to load (without the
53file extension), and language is the language set containing it (ie,
54english). If the second parameter is missing, the default language set
55in your application/config/config.php file will be used.
56
57Fetching a Line of Text
58=======================
59
60Once your desired language file is loaded you can access any line of
61text using this function::
62
63 $this->lang->line('language_key');
64
65Where language_key is the array key corresponding to the line you wish
66to show.
67
68Note: This function simply returns the line. It does not echo it for
69you.
70
71Using language lines as form labels
72-----------------------------------
73
74This feature has been deprecated from the language library and moved to
75the lang() function of the :doc:`Language
76helper <../helpers/language_helper>`.
77
78Auto-loading Languages
79======================
80
81If you find that you need a particular language globally throughout your
82application, you can tell CodeIgniter to
83:doc:`auto-load <../general/autoloader>` it during system
84initialization. This is done by opening the
85application/config/autoload.php file and adding the language(s) to the
86autoload array.
87
88