blob: ec678cd21427c6cc313bd53b1ffc9997f75c08de [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
Derek Jonesd095adf2011-10-05 15:55:20 -050042 $lang['error_email_missing'] = "You must submit an email address";
43 $lang['error_url_missing'] = "You must submit a URL";
44 $lang['error_username_missing'] = "You must submit a username";
Derek Jones8ede1a22011-10-05 13:34:52 -050045
46Loading A Language File
47=======================
48
49In order to fetch a line from a particular file you must load the file
50first. Loading a language file is done with the following code::
51
52 $this->lang->load('filename', 'language');
53
54Where filename is the name of the file you wish to load (without the
55file extension), and language is the language set containing it (ie,
56english). If the second parameter is missing, the default language set
57in your application/config/config.php file will be used.
58
59Fetching a Line of Text
60=======================
61
62Once your desired language file is loaded you can access any line of
63text using this function::
64
65 $this->lang->line('language_key');
66
67Where language_key is the array key corresponding to the line you wish
68to show.
69
70Note: This function simply returns the line. It does not echo it for
71you.
72
73Using language lines as form labels
74-----------------------------------
75
76This feature has been deprecated from the language library and moved to
77the lang() function of the :doc:`Language
78helper <../helpers/language_helper>`.
79
80Auto-loading Languages
81======================
82
83If you find that you need a particular language globally throughout your
84application, you can tell CodeIgniter to
85:doc:`auto-load <../general/autoloader>` it during system
86initialization. This is done by opening the
87application/config/autoload.php file and adding the language(s) to the
88autoload array.
89
90