Jump to content

Recommended Posts

Posted

langswitcher.png

 

Hello :)
 
Unfortunately, can't do it as addon.
So we have to work a little  /ok
 
 
FIrstly need open FluxCP/lib/Flux.php
 
Find this

if ($lang=self::config('DefaultLanguage')) {
$current = $addonName ? FLUX_ADDON_DIR."/$addonName/lang/$lang.php" : FLUX_LANG_DIR."/$lang.php";
}

And add few lines after

// [Sanasol] LangSwitcher
$dictionary = array("en" => "en_us", "ru" => "ru_ru"); // keeping bad guys from use ../../../../
if(!empty($_COOKIE["language"]) && array_key_exists($_COOKIE["language"], $dictionary))
{
	$lang = $dictionary[$_COOKIE["language"]];
	$current = $addonName ? FLUX_ADDON_DIR."/$addonName/lang/$lang.php" : FLUX_LANG_DIR."/$lang.php";
}
// [Sanasol] LangSwitcher

Here you should change $dictionary to your own lang list. For example: "lang_key" => "lang_file" and create translation file in FluxCP/lang/ named lang_file.php
 
 
And now output switcher
Open FluxCP/themes/your_theme/footer.php or other theme part where you want to place it.
 
For default theme I added to footer.php some magic code
 
before this line

<?php if (Flux::config('ShowCopyright')): ?>

add this

<tr>
	<td colspan="3"></td>
	<td>
		<script>
			function setCookie(key, value) {
				var expires = new Date();
				expires.setTime(expires.getTime() + expires.getTime()); // never expires 
				document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
			}
			
			function getCookie(key) {
				var keyValue = document.cookie.match('(^| ?' + key + '=([^;]*)(;|$)');
				return keyValue ? keyValue[2] : null;
			}
			
			$(document).ready(function(){
				$("a[data-lang]").click(function(e){
					e.preventDefault();
					if(getCookie('language') != $(this).data("lang"))
					{
						setCookie('language', $(this).data("lang"));
						reload();
					}
				});
				
				$("a[data-lang]").each(function(i){
					if(getCookie('language') == $(this).data("lang"))
					{
						$(this).css("font-weight","700");
					}
				});
			});
		</script>
		<p>
			<a href="#" data-lang="en">English</a>/<a href="#" data-lang="ru">Russian</a>
		</p>
	</td>
	<td></td>
</tr>

Very simple code.
You see lang links where data-lang = lang_key
 
 
Thats all!
 
 
When you save it and visit your site you will see something like this
 
9a2df3ccd5873be2f94613a159a6.png
 
Now you can switch language in your FluxCP.
 
Demo available here: http://ro.sanasol.ws/demo/fluxcp/?module=woe
Only this page have differences in langs :)
 
 
Interesting fact: drawing logo (two flags with poring(from DeviantArt)) took more time than writing code  /heh

  • Upvote 1
  • 3 years later...
Posted

After 3 Years i have test it, but din't work for me. Any other Codes for language switch on one flux cp?  i found nothing in www.

  • 4 months later...
  • 1 month later...
  • 11 months later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...