diff options
author | Robin Appelman <icewind1991@gmail.com> | 2011-06-20 14:33:02 +0200 |
---|---|---|
committer | Robin Appelman <icewind1991@gmail.com> | 2011-06-20 14:33:31 +0200 |
commit | 76b12c4ae0ea9941b030f0a13786d0ac3fc32f76 (patch) | |
tree | d46fff7789a676d1912fcbf65c5d94cf9b95d783 | |
parent | a7b7f5a76ce7fe3fb371f008d5de9c749ac5c1c1 (diff) | |
download | nextcloud-server-76b12c4ae0ea9941b030f0a13786d0ac3fc32f76.tar.gz nextcloud-server-76b12c4ae0ea9941b030f0a13786d0ac3fc32f76.zip |
add settings option for language
-rw-r--r-- | lib/l10n.php | 37 | ||||
-rw-r--r-- | settings/ajax/setlanguage.php | 24 | ||||
-rw-r--r-- | settings/index.php | 7 | ||||
-rw-r--r-- | settings/js/main.js | 14 | ||||
-rw-r--r-- | settings/templates/index.php | 48 |
5 files changed, 99 insertions, 31 deletions
diff --git a/lib/l10n.php b/lib/l10n.php index f760d78c72b..729310825dd 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -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 diff --git a/settings/ajax/setlanguage.php b/settings/ajax/setlanguage.php new file mode 100644 index 00000000000..672836afe0f --- /dev/null +++ b/settings/ajax/setlanguage.php @@ -0,0 +1,24 @@ +<?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" ))); +} + +?> diff --git a/settings/index.php b/settings/index.php index 1a442eca811..e2a73a5d9f3 100644 --- a/settings/index.php +++ b/settings/index.php @@ -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(); ?> diff --git a/settings/js/main.js b/settings/js/main.js index e05fc68743c..010225bcb27 100644 --- a/settings/js/main.js +++ b/settings/js/main.js @@ -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; + }); } ); diff --git a/settings/templates/index.php b/settings/templates/index.php index 2d5e9d9140f..f8ef9faf1d7 100644 --- a/settings/templates/index.php +++ b/settings/templates/index.php @@ -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> |