Jump to content

FluxCP "Addon" - Language Switcher


Sanasol

Recommended Posts


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  185
  • Reputation:   53
  • Joined:  01/04/12
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  197
  • Reputation:   13
  • Joined:  05/14/12
  • Last Seen:  

Awesome addons Sano thanks for sharing  /no1

Link to comment
Share on other sites

  • 3 years later...

  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.01
  • Content Count:  62
  • Reputation:   5
  • Joined:  08/23/17
  • Last Seen:  

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.

Link to comment
Share on other sites

  • 4 months later...

  • Group:  Members
  • Topic Count:  83
  • Topics Per Day:  0.03
  • Content Count:  188
  • Reputation:   3
  • Joined:  12/17/16
  • Last Seen:  

Not working with FluxCP 2017 Versions

Link to comment
Share on other sites

  • 1 month later...

  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.02
  • Content Count:  242
  • Reputation:   37
  • Joined:  02/25/18
  • Last Seen:  

On 12/1/2018 at 10:58 AM, Diana said:

Not working with FluxCP 2017 Versions

same form me... any update @Sanasol ???

Link to comment
Share on other sites

  • 11 months later...

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  1
  • Reputation:   1
  • Joined:  02/05/16
  • Last Seen:  

Language switcher Fluxcp rA by S-anasol support 2017+
Link https://github.com/rathena/FluxCP/pull/226

  • Upvote 1
Link to comment
Share on other sites

×
×
  • Create New...