Created function get_lang() to retrieve language locale

svn path=/trunk/; revision=935
This commit is contained in:
Curtis Gedak 2008-10-16 19:58:14 +00:00
parent 7c077aad2c
commit 6a28b6810a
3 changed files with 17 additions and 0 deletions

View File

@ -1,5 +1,8 @@
2008-10-16 Curtis Gedak <gedakc@gmail.com>
* include/Utils.h,
src/Utils.cc: Created function get_lang()
* src/main.cc: Update copyright years
2008-10-15 Curtis Gedak <gedakc@gmail.com>

View File

@ -141,6 +141,7 @@ public:
static Glib::ustring delete_mtoolsrc_file( const char file_name[] ) ;
static Glib::ustring trim( const Glib::ustring & src, const Glib::ustring & c = " \t\r\n" ) ;
static Glib::ustring cleanup_cursor( const Glib::ustring & text ) ;
static Glib::ustring get_lang() ;
};

View File

@ -20,6 +20,7 @@
#include <sstream>
#include <iomanip>
#include <regex.h>
#include <locale.h>
namespace GParted
{
@ -355,5 +356,17 @@ Glib::ustring Utils::cleanup_cursor( const Glib::ustring & text )
return str;
}
Glib::ustring Utils::get_lang()
{
//Extract base language from string that may look like "en_CA.UTF-8"
// and return in the form "en-CA"
Glib::ustring lang = setlocale( LC_CTYPE, NULL ) ;
Glib::ustring sought = "_" ;
Glib::ustring replacement = "-" ;
lang = Utils::regexp_label( lang .c_str(), "^([^.]*)") ;
lang .replace( lang .find(sought), sought .size(), replacement ) ;
return lang ;
}
} //GParted..