2017-02-20 18:29:06 +01:00
( function ( ) {
var LS _LANG = "CRYPTPAD_LANG" ;
var getStoredLanguage = function ( ) { return localStorage . getItem ( LS _LANG ) ; } ;
var getBrowserLanguage = function ( ) { return navigator . language || navigator . userLanguage ; } ;
var getLanguage = function ( ) { return getStoredLanguage ( ) || getBrowserLanguage ( ) ; } ;
var language = getLanguage ( ) ;
// add your module to this map so it gets used
var map = {
'fr' : 'Français' ,
'es' : 'Español' ,
'pl' : 'Polski' ,
'de' : 'Deutsch' ,
'pt-br' : 'Português do Brasil'
} ;
var req = [ '/customize/translations/messages.js' ] ;
if ( language && map [ language ] ) { req . push ( '/customize/translations/messages.' + language + '.js' ) ; }
req . push ( '/bower_components/jquery/dist/jquery.min.js' ) ;
define ( req , function ( Default , Language ) {
2016-09-14 18:08:52 +02:00
var $ = window . jQuery ;
2014-11-03 16:07:39 +01:00
2017-02-20 18:29:06 +01:00
var externalMap = JSON . parse ( JSON . stringify ( map ) ) ;
2014-11-03 16:07:39 +01:00
2017-02-20 18:29:06 +01:00
map . en = 'English' ;
2016-09-14 18:08:52 +02:00
var defaultLanguage = 'en' ;
2014-11-03 16:07:39 +01:00
2016-09-14 18:08:52 +02:00
var messages ;
2016-07-11 17:36:53 +02:00
2017-02-20 18:29:06 +01:00
if ( ! Language || ! language || language === defaultLanguage || language === 'default' || ! map [ language ] ) {
2016-09-15 18:35:09 +02:00
messages = Default ;
}
else {
// Add the translated keys to the returned object
2017-02-20 18:29:06 +01:00
messages = $ . extend ( true , { } , Default , Language ) ;
2016-09-15 18:35:09 +02:00
}
2016-07-11 17:36:53 +02:00
2017-02-20 18:29:06 +01:00
messages . _languages = map ;
2016-10-25 15:22:35 +02:00
2017-02-20 18:29:06 +01:00
messages . _checkTranslationState = function ( cb ) {
if ( typeof ( cb ) !== "function" ) { return ; }
2016-10-24 11:41:36 +02:00
var missing = [ ] ;
2017-02-20 18:29:06 +01:00
var reqs = [ ] ;
Object . keys ( externalMap ) . forEach ( function ( code ) {
reqs . push ( '/customize/translations/messages.' + code + '.js' ) ;
} ) ;
require ( reqs , function ( ) {
var langs = arguments ;
Object . keys ( externalMap ) . forEach ( function ( code , i ) {
var translation = langs [ i ] ;
2017-02-23 11:45:00 +01:00
var updated = { } ;
Object . keys ( Default ) . forEach ( function ( k ) {
if ( /^updated_[0-9]+_/ . test ( k ) && ! translation [ k ] ) {
var key = k . split ( '_' ) . slice ( 2 ) . join ( '_' ) ;
// Make sure we don't already have an update for that key. It should not happen
// but if it does, keep the latest version
if ( updated [ key ] ) {
var ek = updated [ key ] ;
if ( parseInt ( ek . split ( '_' ) [ 1 ] ) > parseInt ( k . split ( '_' ) [ 1 ] ) ) { return ; }
}
updated [ key ] = k ;
}
} ) ;
2017-02-20 18:29:06 +01:00
Object . keys ( Default ) . forEach ( function ( k ) {
2017-02-21 18:43:26 +01:00
if ( /^_/ . test ( k ) ) { return ; }
2017-02-23 11:45:00 +01:00
if ( ! translation [ k ] || updated [ k ] ) {
if ( updated [ k ] ) {
missing . push ( [ code , k , 2 , 'out.' + updated [ k ] ] ) ;
return ;
}
2017-02-21 10:53:30 +01:00
missing . push ( [ code , k , 1 ] ) ;
2017-02-20 18:29:06 +01:00
}
} ) ;
Object . keys ( translation ) . forEach ( function ( k ) {
2017-02-21 18:43:26 +01:00
if ( /^_/ . test ( k ) ) { return ; }
2017-02-20 18:29:06 +01:00
if ( ! Default [ k ] ) {
2017-02-21 10:53:30 +01:00
missing . push ( [ code , k , 0 ] ) ;
2017-02-20 18:29:06 +01:00
}
} ) ;
2016-10-24 11:41:36 +02:00
} ) ;
2017-02-20 18:29:06 +01:00
cb ( missing ) ;
2016-10-24 11:41:36 +02:00
} ) ;
} ;
2016-10-25 15:22:35 +02:00
2016-09-15 18:35:09 +02:00
// Get keys with parameters
2016-09-14 18:08:52 +02:00
messages . _getKey = function ( key , argArray ) {
if ( ! messages [ key ] ) { return '?' ; }
var text = messages [ key ] ;
2017-02-21 12:29:47 +01:00
if ( typeof ( text ) === 'string' ) {
return text . replace ( /\{(\d+)\}/g , function ( str , p1 ) {
return argArray [ p1 ] || null ;
} ) ;
} else {
return text ;
}
2016-09-14 18:08:52 +02:00
} ;
2016-07-11 17:36:53 +02:00
2017-02-20 18:29:06 +01:00
// Add handler to the language selector
var storeLanguage = function ( l ) {
localStorage . setItem ( LS _LANG , l ) ;
} ;
messages . _initSelector = function ( $select ) {
var selector = $select || $ ( '#language-selector' ) ;
if ( ! selector . length ) { return ; }
var $button = $ ( selector ) . find ( 'button .buttonTitle' ) ;
// Select the current language in the list
var option = $ ( selector ) . find ( '[data-value="' + language + '"]' ) ;
if ( $ ( option ) . length ) {
$button . text ( $ ( option ) . text ( ) ) ;
}
else {
$button . text ( 'English' ) ;
}
// Listen for language change
$ ( selector ) . find ( 'a.languageValue' ) . on ( 'click' , function ( ) {
var newLanguage = $ ( this ) . attr ( 'data-value' ) ;
storeLanguage ( newLanguage ) ;
if ( newLanguage !== language ) {
window . location . reload ( ) ;
}
} ) ;
} ;
2016-11-16 17:11:48 +01:00
var translateText = function ( i , e ) {
var $el = $ ( e ) ;
var key = $el . data ( 'localization' ) ;
$el . html ( messages [ key ] ) ;
} ;
2017-01-20 18:21:51 +01:00
var translateAppend = function ( i , e ) {
var $el = $ ( e ) ;
var key = $el . data ( 'localization-append' ) ;
$el . append ( messages [ key ] ) ;
} ;
2016-11-16 17:11:48 +01:00
var translateTitle = function ( i , e ) {
var $el = $ ( this ) ;
var key = $el . data ( 'localization-title' ) ;
$el . attr ( 'title' , messages [ key ] ) ;
} ;
2016-12-16 15:20:01 +01:00
var translatePlaceholder = function ( i , e ) {
var $el = $ ( this ) ;
var key = $el . data ( 'localization-placeholder' ) ;
$el . attr ( 'placeholder' , messages [ key ] ) ;
} ;
2016-09-15 18:35:09 +02:00
messages . _applyTranslation = function ( ) {
2016-11-16 17:11:48 +01:00
$ ( '[data-localization]' ) . each ( translateText ) ;
2017-01-20 18:21:51 +01:00
$ ( '[data-localization-append]' ) . each ( translateAppend ) ;
2016-11-16 17:11:48 +01:00
$ ( '#pad-iframe' ) . contents ( ) . find ( '[data-localization]' ) . each ( translateText ) ;
$ ( '[data-localization-title]' ) . each ( translateTitle ) ;
2017-01-06 13:52:30 +01:00
$ ( '[data-localization-placeholder]' ) . each ( translatePlaceholder ) ;
2016-11-16 17:11:48 +01:00
$ ( '#pad-iframe' ) . contents ( ) . find ( '[data-localization-title]' ) . each ( translateTitle ) ;
2016-09-15 18:35:09 +02:00
} ;
2017-02-27 14:29:48 +01:00
/ * m e s s a g e s . d r i v e R e a d m e = ' [ " B O D Y " , { " c l a s s " : " c k e _ e d i t a b l e c k e _ e d i t a b l e _ t h e m e d c k e _ c o n t e n t s _ l t r c k e _ s h o w _ b o r d e r s " , " c o n t e n t e d i t a b l e " : " t r u e " , " s p e l l c h e c k " : " f a l s e " , " s t y l e " : " c o l o r : r g b ( 5 1 , 5 1 , 5 1 ) ; " } , ' +
2017-02-16 17:22:45 +01:00
'[["H1",{},["' + messages . driveReadme _h1 + '",["BR",{},[]]]],["UL",{},[["LI",{},["' + messages . driveReadme _li1 + '",["BR",{},[]],["UL",{},[["LI",{},["' + messages . driveReadme _li1 _1 + '",["BR",{},[]]]]]]]]]]],' +
'{"metadata":{"defaultTitle":"' + messages . driveReadmeTitle + '","title":"' + messages . driveReadmeTitle + '"}}]' ;
2017-02-27 14:29:48 +01:00
* /
messages . driveReadme = '[["H1",{},["' + messages . readme _welcome + '"]],["P",{},["' + messages . readme _p1 + '"]],["P",{},["' + messages . readme _p2 + '"]],["HR",{},[]],["H2",{},["' + messages . readme _cat1 + '",["BR",{},[]]]],["UL",{},[["LI",{},["' + messages . _getKey ( "readme_cat1_l1" , [ '",["STRONG",{},["' + messages . newButton + '"]],"' , '",["STRONG",{},["' + messages . type . pad + '"]],"' ] ) + '"]],["LI",{},["' + messages . readme _cat1 _l2 + '"]],["LI",{},["' + messages . _getKey ( "readme_cat1_l3" , [ '",["STRONG",{},["' + messages . unsortedName + '"]],"' ] ) + '",["UL",{},[["LI",{},["You can click and drag files into folders in the ",["STRONG",{},["Documents"]]," section of your drive and make new folders."]],["LI",{},["Remember to try right clicking on icons because there are often additional menus."]]]]]],["LI",{},["Put old pads in the trash: You can click and drag your pads into the ",["STRONG",{},["Trash"]]," the same way you drag them into folders.",["BR",{},[]]]]]],["P",{},[["BR",{},[]]]],["H2",{},["Make pads like a pro",["BR",{},[]]]],["UL",{},[["LI",{},["The ",["STRONG",{},["Share"]]," button in your pad allows you to give access to collaborators to either ",["STRONG",{},["edit"]]," or to ",["STRONG",{},["view"]]," the pad."]],["LI",{},["Change the title of the pad by clicking on the pencil"]]]],["P",{},[["BR",{},[]]]],["H2",{},["Discover CryptPad apps"]],["UL",{},[["LI",{},["With CryptPad code editor, you can collaborate on code like Javascript and markdown like HTML and Markdown"]],["LI",{},["With CryptPad slide editor, you can make quick presentations using Markdown"]],["LI",{},["With CryptPoll you can take quick votes, especially for scheduling meetings which fit with everybody\'s calander",["BR",{},[]]]]]]]' ;
2017-02-16 17:22:45 +01:00
2016-09-14 18:08:52 +02:00
return messages ;
2017-02-20 18:29:06 +01:00
2014-11-03 16:07:39 +01:00
} ) ;
2017-02-20 18:29:06 +01:00
} ( ) ) ;