Hi this is my view in CodeIgniter for which I want to implement the multi-language country array list. But I am confused about how to call an array in foreach loop with this below given line: echo $this->lang->line('lang_country_list'); Please help me find this confusion of mine
<div class="col-md-4">
<div class="form-group">
<label><?php echo $this->lang->line('lang_country'); ?><span class="text-danger">*</span></label>
<select class="form-control" name="Country" >
<option value=""><?php echo $this->lang->line('lang_select'); ?></option>
<?php if($countries->num_rows()){
foreach($countries->result() as $country){ ?>
<option value="<?php echo $country->name; ?>" data-id="<?php echo $country->id; ?>"> <?php echo $country->name; ?></option> <?php } } ?>
</select>
</div>
</div>
This is my english_lang.php and like this similar array there are many more language file
$lang["lang_country_list"] = array('Afghanistan', 'Albania','Algeria','American Samoa','Andorra','Angola','Anguilla','Anguilla','Antarctica','Antigua and Barbuda','Argentina','Argentina','Armenia','Aruba','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia and Herzegovina','Botswana','Bouvet Island','Brazil','British Indian ocean territory','Brunei','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Canada','Cape Verde','Cayman Islands','Cayman Islands','Central African Republic','Chad','Chile','China','Christmas Island','Cocos Islands','Colombia','Comoros','Democratic Republic of Congo','Republic of Congo','Cook Islands','Costa Rica',"Cote d'Ivoire",'Croatia','Cuba','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','East Timor','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','External territories of Australia','Falkland Islands','Faroe Islands','Fiji islands','Finland','France','French Guiana','French Polynesia','French Southern territories','Gabon','Gambia The','Gaza Strip','Georgia','Germany','Ghana','Gibraltar','Glorioso Islands','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala','Guernsey and Alderney','Guinea','Guinea-Bissau','Guyana','Haiti','Heard Island and McDonald Islands','Honduras','Hong Kong S.A.R.','Hungary','Iceland','India','Indonesia','Iran','Iraq','Ireland','Israel','Italy','Jamaica','Japan','Jersey','Jordan','Kazakhstan','Kenya','Kiribati','Korea North','Korea South','Kuwait','Kyrgyzstan','Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macau S.A.R.','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Man (Isle of)','Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mediterranean Sea','Mexico','Micronesia','Moldova','Monaco','Mongolia','Montserrat','Morocco','Mozambique','Myanmar','Namibia','Nauru','Nepal','Netherlands Antilles','Netherlands The','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island','Northern Mariana Islands','Norway','Oman','Pakistan','Palau','Palestinian Territory Occupied','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn Islands','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russia','Rwanda','Saint Helena','Saint Kitts and Nevis','Saint Lucia','Saint Pierre and Miquelon','Saint Vincent and the Grenadines','Samoa','San Marino','Sao Tome and Principe','Saudi Arabia','Senegal','Serbia','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','Smaller territories of the UK','Solomon Islands','Somalia','South Africa','South Georgia','South Sudan','Spain','Sri Lanka','Sudan','Suriname','Svalbard and Jane Mayen Islands','Swaziland','Sweden','Switzerland','Syria','Taiwan','Tajikistan','Tanzania','Thailand','Togo','Tokelau','Tonga','Trinidad and Tobago','Tunisia','Turkey','Turkmenistan','Turks and Caicos Islands','Tuvalu','Uganda','Ukraine','United Arab Emirates','United Kingdom','United States','United States minor outlying Islands','Uruguay','Uzbekistan','Vanuatu','Vatican city State (Holy see)','Venezuela','Vietnam','Virgin Islands (British)','Virgin Islands (USA)','Wallis and Futuna Islands','West Bank','Western Sahara','Yemen','Yugoslavia','Zambia','Zimbabwe');
This is my french_lang.php file for the french language
$lang["lang_country_list"] = array('Afghanistan','Albanie','Algérie','Samoa américaines','Andorre','Angola','Anguilla/Anguille','Antarctique','Antigua-et-Barbuda','Argentine','Arménie','Aruba','Australie','Autriche','Azerbaïdjan','Bahamas','Bahreïn','Bangladesh','Barbade','Biélorussie','Belgique','Bélize','Bénin','Bermudes','Bhoutan','Bolivie','Bosnie Herzégovine','Botswana','Île Bouvet','Brésil',"Territoire britannique de l'océan Indien",'Brunei','Bulgarie','Burkina Faso','Burundi','Cambodge','Cameroun','Canada','Cap-Vert','Îles Caïmans','République centrafricaine','Tchad','Chili','Chine','Île de Noël','Îles Cocos','Colombie','Comores','République Démocratique du Congo','République du Congo','Îles Cook','Costa Rica',"Côte d'Ivoire",'Croatie','Cuba','Chypre','République Tchèque','Danemark','Djibouti','Dominique','République dominicaine','Timor oriental','Équateur','Égypte','Le Salvador','Guinée Équatoriale','Érythrée','Estonie','Éthiopie',"Territoires extérieurs de l'Australie",'Îles Falkland','Îles Féroé','Îles Fidji','Finlande','France','Guyane française','Polynésie française','Territoires français du Sud','Gabon','Gambie','La bande de Gaza','Géorgie','Allemagne','Ghana','Gibraltar','Îles Glorieuses','Grèce','Groenland','Grenade','Guadeloupe','Guam','Guatemala','Guernesey et Aurigny','Guinée','Guinée-Bissau','Guyane','Haïti','Île Heard et Îles McDonald','Honduras','Hong Kong S.A.R.','Hongrie','Islande','Inde','Indonésie','Iran','Irak','Irlande','Israël','Italie','Jamaïque','Japon','New Jersey','Jordanie','Kazakhstan','Kenya','Kiribati','Corée du Nord','Corée du Sud','Koweït','Kirghizistan','Laos','Lettonie','Liban','Lesotho','Libéria','Libye','Liechtenstein','Lituanie','Luxembourg','Macao S.A.R.','Macédoine','Madagascar','Malawi','Malaisie','Maldives','Mali','Malte','Île de Man','Îles Marshall','Martinique','Mauritanie','Maurice','Mayotte','Mer Méditerranée','Mexique','Micronésie','Moldavie','Monaco','Mongolie','Montserrat','Maroc','Mozambique','Birmanie','Namibie','Nauru','Népal','Antilles néerlandaises','Les Pays-Bas','Nouvelle-Calédonie','Nouvelle-Zélande','Nicaragua','Niger','Nigeria','Nioué','Île de Norfolk','Îles Mariannes du Nord','Norvège','Oman','Pakistan','Palaos','Territoire palestinien occupé','Panama','Papouasie Nouvelle Guinée','Paraguay','Pérou','Philippines','Îles Pitcairn','Pologne','Portugal','Porto Rico','Qatar','Île de la Réunion','Roumanie','Russie','Rwanda','Sainte-Hélène','Saint-Christophe-et-Niévès','Sainte-Lucie','Saint-Pierre-et-Miquelon','Saint-Vincent-et-les-Grenadines','Samoa','Saint Marin','Sao Tomé et Principe','Arabie Saoudite','Sénégal','Serbie','Seychelles','Sierra Leone','Singapour','Slovaquie','Slovénie','Petits territoires du Royaume-Uni','Îles Salomon','Somalie','Afrique du Sud','Géorgie du Sud','Soudan du sud','Espagne','Sri Lanka','Soudan','Surinam','Îles Svalbard et Jane Mayen','Swaziland','Suède','Suisse','Syrie','Taïwan','Tadjikistan','Tanzanie','Thaïlande','Togo','Tokélaou','Tonga','Trinité-et-Tobago','Tunisie','Turquie','Turkménistan','Îles Turques et Caïques','Tuvalu','Ouganda','Ukraine','Émirats arabes unis','Royaume-Uni','États-Unis','Îles périphériques mineures des Etats-Unis','Uruguay','Ouzbékistan','Vanuatu','État de la Cité du Vatican (Saint-Siège)','Venezuela','Viêt Nam','Îles Vierges (britanniques)','Îles Vierges (États-Unis)','Îles Wallis et Futuna','Cisjordanie','Sahara Occidental.','Yémen','Yougoslavie','Zambie','Zimbabwe');
And please correct me if i am wrong somewhere
CodePudding user response:
This code works for me in core php. change file include according to CodeIgniter and then apply that solution. I think it will work for you
<?php
include("language.php");
?>
<div class="col-md-4">
<div class="form-group">
<label><span class="text-danger">*</span></label>
<select class="form-control" name="Country" >
<option value=""><?php echo "Select Country" ?></option>
<?php if(isset($lang["lang_country_list"])){
foreach($lang["lang_country_list"] as $country){ ?>
<option value="<?php echo $country; ?>" data-id="<?php echo $country; ?>">
<?php echo $country; ?></option>
<?php
}
} ?>
</select>
</div>
</div>
language.php file:
<?php
$lang["lang_country_list"] = array('Afghanistan', 'Albania','Algeria','American Samoa','Andorra','Angola','Anguilla','Anguilla','Antarctica','Antigua and Barbuda','Argentina','Argentina','Armenia','Aruba','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia and Herzegovina','Botswana','Bouvet Island','Brazil','British Indian ocean territory','Brunei','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Canada','Cape Verde','Cayman Islands','Cayman Islands','Central African Republic','Chad','Chile','China','Christmas Island','Cocos Islands','Colombia','Comoros','Democratic Republic of Congo','Republic of Congo','Cook Islands','Costa Rica',"Cote d'Ivoire",'Croatia','Cuba','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','East Timor','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','External territories of Australia','Falkland Islands','Faroe Islands','Fiji islands','Finland','France','French Guiana','French Polynesia','French Southern territories','Gabon','Gambia The','Gaza Strip','Georgia','Germany','Ghana','Gibraltar','Glorioso Islands','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala','Guernsey and Alderney','Guinea','Guinea-Bissau','Guyana','Haiti','Heard Island and McDonald Islands','Honduras','Hong Kong S.A.R.','Hungary','Iceland','India','Indonesia','Iran','Iraq','Ireland','Israel','Italy','Jamaica','Japan','Jersey','Jordan','Kazakhstan','Kenya','Kiribati','Korea North','Korea South','Kuwait','Kyrgyzstan','Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macau S.A.R.','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Man (Isle of)','Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mediterranean Sea','Mexico','Micronesia','Moldova','Monaco','Mongolia','Montserrat','Morocco','Mozambique','Myanmar','Namibia','Nauru','Nepal','Netherlands Antilles','Netherlands The','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island','Northern Mariana Islands','Norway','Oman','Pakistan','Palau','Palestinian Territory Occupied','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn Islands','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russia','Rwanda','Saint Helena','Saint Kitts and Nevis','Saint Lucia','Saint Pierre and Miquelon','Saint Vincent and the Grenadines','Samoa','San Marino','Sao Tome and Principe','Saudi Arabia','Senegal','Serbia','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','Smaller territories of the UK','Solomon Islands','Somalia','South Africa','South Georgia','South Sudan','Spain','Sri Lanka','Sudan','Suriname','Svalbard and Jane Mayen Islands','Swaziland','Sweden','Switzerland','Syria','Taiwan','Tajikistan','Tanzania','Thailand','Togo','Tokelau','Tonga','Trinidad and Tobago','Tunisia','Turkey','Turkmenistan','Turks and Caicos Islands','Tuvalu','Uganda','Ukraine','United Arab Emirates','United Kingdom','United States','United States minor outlying Islands','Uruguay','Uzbekistan','Vanuatu','Vatican city State (Holy see)','Venezuela','Vietnam','Virgin Islands (British)','Virgin Islands (USA)','Wallis and Futuna Islands','West Bank','Western Sahara','Yemen','Yugoslavia','Zambia','Zimbabwe');?>