Skip to content
Snippets Groups Projects
Commit 76b12c4a authored by Robin Appelman's avatar Robin Appelman
Browse files

add settings option for language

parent a7b7f5a7
No related branches found
No related tags found
No related merge requests found
......@@ -198,19 +198,7 @@ class OC_L10N{
$available = $app;
}
else{
$dir = self::findI18nDir( $app );
if( file_exists($dir)){
$dh = opendir($dir);
while(( $file = readdir( $dh )) !== false ){
if( substr( $file, -4, 4 ) == '.php' ){
$i = substr( $file, 0, -4 );
if( $i != '' ){
$available[] = $i;
}
}
}
closedir($dh);
}
$available=self::findAvailableLanguages( $app );
}
if( isset($_SESSION['user_id']) && $_SESSION['user_id'] && OC_PREFERENCES::getValue( $_SESSION['user_id'], 'core', 'lang' )){
$lang = OC_PREFERENCES::getValue( $_SESSION['user_id'], 'core', 'lang' );
......@@ -255,4 +243,27 @@ class OC_L10N{
}
return $i18ndir;
}
/**
* @brief find all available languages for an app
* @param $app App that needs to be translated
* @returns array an array of available languages
*/
public static function findAvailableLanguages( $app=null ){
$available=array('en');//english is always available
$dir = self::findI18nDir( $app );
if( file_exists($dir)){
$dh = opendir($dir);
while(( $file = readdir( $dh )) !== false ){
if( substr( $file, -4, 4 ) == '.php' and strlen($file)==6 ){
$i = substr( $file, 0, -4 );
if( $i != '' ){
$available[] = $i;
}
}
}
closedir($dh);
}
return $available;
}
}
\ No newline at end of file
<?php
// Init owncloud
require_once('../../lib/base.php');
// We send json data
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_USER::isLoggedIn()){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
exit();
}
// Get data
if( isset( $_POST['lang'] ) ){
$lang=$_POST['lang'];
OC_PREFERENCES::setValue( $_SESSION['user_id'], 'core', 'lang', $lang );
echo json_encode( array( "status" => "success", "data" => array( "message" => "Language changed" )));
}else{
echo json_encode( array( "status" => "error", "data" => array( "message" => "Invalid request" )));
}
?>
......@@ -18,11 +18,18 @@ $free=OC_FILESYSTEM::free_space();
$total=$free+$used;
$relative=round(($used/$total)*100);
$lang=OC_PREFERENCES::getValue( $_SESSION['user_id'], 'core', 'lang', 'en' );
$languages=OC_L10N::findAvailableLanguages();
//put the current language in the front
unset($languages[array_search($lang,$languages)]);
array_unshift($languages,$lang);
// Return template
$tmpl = new OC_TEMPLATE( "settings", "index", "admin");
$tmpl->assign('usage',OC_HELPER::humanFileSize($used));
$tmpl->assign('total_space',OC_HELPER::humanFileSize($total));
$tmpl->assign('usage_relative',$relative);
$tmpl->assign('languages',$languages);
$tmpl->printPage();
?>
......@@ -18,4 +18,18 @@ $(document).ready(function(){
});
return false;
});
$("#languageinput").change( function(){
// Serialize the data
var post = $( "#languageinput" ).serialize();
// Ajax foo
$.post( 'ajax/setlanguage.php', post, function(data){
if( data.status == "success" ){
}
else{
$('#passworderror').html( data.data.message );
}
});
return false;
});
} );
......@@ -8,23 +8,35 @@
<form id="passwordform">
<fieldset>
<legend>Change Password</legend>
<div id="passwordchanged">You're password got changed</div>
<div id="passworderror"></div>
<p>
<label for="pass1">Old password:</label>
<input type="password" id="pass1" name="oldpassword" />
</p>
<p>
<label for="pass2">New password :</label>
<input type="password" id="pass2" name="password" />
</p>
<p>
<input type="checkbox" id="show" name="show" />
<label for="show">Show new password</label>
</p>
<p class="form_footer">
<input id="passwordbutton" class="prettybutton" type="submit" value="Save" />
</p>
<legend>Change Password</legend>
<div id="passwordchanged">You're password got changed</div>
<div id="passworderror"></div>
<p>
<label for="pass1">Old password:</label>
<input type="password" id="pass1" name="oldpassword" />
</p>
<p>
<label for="pass2">New password :</label>
<input type="password" id="pass2" name="password" />
</p>
<p>
<input type="checkbox" id="show" name="show" />
<label for="show">Show new password</label>
</p>
<p class="form_footer">
<input id="passwordbutton" class="prettybutton" type="submit" value="Save" />
</p>
</fieldset>
</form>
<form id="languageform">
<fieldset>
<legend>Language</legend>
<label for=''></label>
<select id="languageinput" name='lang'>
<?php foreach($_['languages'] as $language):?>
<option value='<?php echo $language;?>'><?php echo $language;?></option>
<?php endforeach;?>
</select>
</fieldset>
</form>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment