benegedeniz / langy
Simple yet powerful PHP language management class.
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/benegedeniz/langy
Requires
- php: >=7.0.0
README
A simple PHP language management class.
Requirements
- PHP 7 or upper.
Installation
If you are using Composer, you can run the following command:
composer require benegedeniz/langy
Or download Langy directly and extract them to your web directory.
Usage
<?php
require_once __DIR__ . "/src/langy.php"; // Requiring Langy.
$lang = new Langy;
// Setting the language file extension. (If you don't set it, this will default to "langy".)
$lang->setLangExt("langy");
// Setting the folder that contains language files. (Language files must end with the extension you set and must be in JSON format.)
$lang->setLangDir("languages");
// Setting the language. (This must be the name of the desired language file. Exclude extension.)
$lang->setLang("en");
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $lang->echo("title"); // Echoing a language item from the language file. ?></title>
</head>
<body>
<div style="text-align:center">
<h1><?php
// Assigning language item to variable.
$text = $lang->get("pageContent.header");
echo $text;
?>
</h1>
<h3>Langy developer: <?php $lang->echo("pageContent.classAuthor"); ?></h3><br>
<h2>An example text: <?php $lang->echo("pageContent.helloLangy.helloMsg"); ?></h2>
<h2>An example text with using variables: <?php $lang->echo("pageContent.helloLangy.helloMsgWithVars", ["iamavariable" => "Langy"]); ?></h2>
</div>
</body>
</html>