Index: /CKLangTool/trunk/_dev/build.xml
===================================================================
--- /CKLangTool/trunk/_dev/build.xml (revision 7310)
+++ /CKLangTool/trunk/_dev/build.xml (revision 7311)
@@ -27,4 +27,5 @@
+
@@ -39,4 +40,5 @@
+
Index: /CKLangTool/trunk/_source/includes/ckmetaformat.js
===================================================================
--- /CKLangTool/trunk/_source/includes/ckmetaformat.js (revision 7311)
+++ /CKLangTool/trunk/_source/includes/ckmetaformat.js (revision 7311)
@@ -0,0 +1,114 @@
+/*
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
+For licensing, see LICENSE.html or http://ckeditor.com/license
+*/
+
+importPackage( java.util.regex );
+importClass( java.text.SimpleDateFormat );
+
+( function()
+{
+ /*
+ * An array with missing keys in current translation.
+ */
+ var metaInformation;
+
+ CKLANGTOOL.meta = function()
+ {
+ return {
+ run : function()
+ {
+ metaInformation = loadMetaInformation();
+
+ var file = new File( CKLANGTOOL.destinationDir, 'meta.txt' );
+ CKLANGTOOL.io.saveFile( file, processFile(CKLANGTOOL.templateFile), false );
+
+ print( "Process completed." );
+ }
+ };
+ };
+
+ /**
+ * Meta file stores an extra information about each string (context, user friendly description).
+ * The format is:
+ * fieldId = information
+ *
+ * Sample entry:
+ * link.noUrl = Error message shown to the user when URL field is empty.
+ */
+ function loadMetaInformation()
+ {
+ if (!CKLANGTOOL.metaFile)
+ return {};
+
+ var lines = CKLANGTOOL.io.readFileIntoArray(CKLANGTOOL.metaFile);
+ var meta = {};
+
+ for ( var j = 0 ; j < lines.length ; j++ )
+ {
+ var line = lines[ j ];
+ if ( match = line.match( /^\s*([a-z0-9_.]+)\s*=\s*(.*)\s*$/i ) )
+ {
+ meta[match[1]] = match[2];
+ }
+ }
+ return meta;
+ }
+
+ function printObject( prefix, o )
+ {
+ var result = [];
+
+ for ( var key in o )
+ {
+ var entry = o[ key ],
+ entryName = prefix ? ( prefix + '.' + key ) : key;
+
+ if ( typeof entry == 'object' )
+ result.push( printObject( entryName, entry ) );
+ else
+ result.push( poEntry( entryName, entry ) );
+ }
+
+ return result.join( '' );
+ }
+
+ function msgstrEscape( str )
+ {
+ return str.replace( /"/g, '\\"' ).replace( /\r\n|\n/g, '\\n"$&"' );
+ }
+
+ /**
+ * Generate a PO translation entry with the following schematic structure:
+ * whte-space
+ * # translator-comments
+ * #.extracted-comments
+ * #:reference...
+ * #,flag...
+ * #|msgid previous-untranslated-string
+ * msid untranslated-string
+ * msstr translated-string
+ *
+ * @param {String} id The untranslated string part.
+ * @param {String} str The translated-string part.
+ * @param {String} [ comment1, comment2... ] Translator comments.
+ */
+ function poEntry( id, str, comment )
+ {
+ var str = "";
+ if ( metaInformation[id] )
+ str = metaInformation[id];
+ return id + ' = ' + str + '\n';
+ }
+
+ function processFile( file )
+ {
+ // License Info
+ var date = new Date(),
+ license = '# Copyright (c) 2003-' + date.getFullYear() + ', CKSource - Frederico Knabben. All rights reserved.\n# For licensing, see LICENSE.html or http://ckeditor.com/license\n\n';
+
+ var language = CKLANGTOOL.loadLanguageFile( file, 'json' );
+ return license + printObject( '', language.translation );
+ }
+
+})();
Index: /CKLangTool/trunk/_source/langtool.js
===================================================================
--- /CKLangTool/trunk/_source/langtool.js (revision 7310)
+++ /CKLangTool/trunk/_source/langtool.js (revision 7311)
@@ -56,4 +56,5 @@
CKLANGTOOL.load( 'cklangtool.includes.ckjpformat' );
CKLANGTOOL.load( 'cklangtool.includes.ckpoformat' );
+CKLANGTOOL.load( 'cklangtool.includes.ckmetaformat' );
CKLANGTOOL.load( 'cklangtool.includes.po_parser' );
CKLANGTOOL.load( 'cklangtool.includes.io' );
@@ -68,8 +69,9 @@
+ '\n\nOptions:'
- + '\n[-f|--format]=json|gettext|jprops Format of language file when update from or export translation entries to, default to json.'
+ + '\n[-f|--format]=json|gettext|jprops|meta Format of language file when update from or export translation entries to, default to json.'
+ '\n\t json - A private JavaScript format used as runtime language files in CKEditor.'
- + '\n\t getext - The versatile GNU Gettext format, simplified to fit for CKEditor.'
+ + '\n\t gettext - The versatile GNU Gettext format, simplified to fit for CKEditor.'
+ '\n\t jprops - The Java Properties file format.'
+ + '\n\t meta - The meta file with context information (used by the gettext method).'
+ '\n[-m|--metafile]=path Specify the path to an optional meta file which used only by the Gettext format for context information.'
+ '\n[-c|--config]=path Specify the path to an optional configuration file.'
@@ -159,6 +161,13 @@
if ( action == 'update' )
{
- var translator = new CKLANGTOOL.translator();
- translator.run( CKLANGTOOL.destinationDir || CKLANGTOOL.languageDir );
+ if ( CKLANGTOOL.format == 'meta' )
+ {
+ new CKLANGTOOL.meta().run();
+ }
+ else
+ {
+ var translator = new CKLANGTOOL.translator();
+ translator.run( CKLANGTOOL.destinationDir || CKLANGTOOL.languageDir );
+ }
}
// Export translations to other formats.
Index: /CKLangTool/trunk/test/_assets/meta/en.js
===================================================================
--- /CKLangTool/trunk/test/_assets/meta/en.js (revision 7311)
+++ /CKLangTool/trunk/test/_assets/meta/en.js (revision 7311)
@@ -0,0 +1,62 @@
+/*
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
+For licensing, see LICENSE.html or http://ckeditor.com/license
+*/
+
+CKEDITOR.plugins.setLang( 'uicolor', 'en',
+{
+ uicolor :
+ {
+ title : 'UI Color Picker',
+ preview : 'Live preview',
+ config : 'Paste this string into your config.js file',
+ predefined : 'Predefined color sets'
+ },
+
+ accessibilityHelp :
+ {
+ title : 'Accessibility Instructions',
+ legend :
+ [
+ {
+ name : 'General',
+ items :
+ [
+ {
+ name : 'Editor Toolbar',
+ legend:
+ 'Press ${toolbarFocus} to navigate to the toolbar. ' +
+ 'Move to the next and previous toolbar group with TAB and SHIFT-TAB. ' +
+ 'Move to the next and previous toolbar button with RIGHT ARROW or LEFT ARROW. ' +
+ 'Press SPACE or ENTER to activate the toolbar button.'
+ },
+ {
+ name : 'Editor Dialog'
+ }
+ ]
+ },
+ {
+ name : 'Commands',
+ items :
+ [
+ {
+ name : ' Undo command',
+ legend :
+ 'Press ${undo}'
+ },
+ {
+ name : ' Redo command',
+ legend :
+ 'Press ${redo}'
+ },
+ {
+ name : ' Bold command',
+ legend : 'Press ${bold}'
+ }
+ ]
+ }
+ ],
+ contents : 'Help Contents. To close this dialog press ESC.'
+ }
+
+});
Index: /CKLangTool/trunk/test/_assets/meta/meta.txt
===================================================================
--- /CKLangTool/trunk/test/_assets/meta/meta.txt (revision 7311)
+++ /CKLangTool/trunk/test/_assets/meta/meta.txt (revision 7311)
@@ -0,0 +1,17 @@
+# Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
+# For licensing, see LICENSE.html or http://ckeditor.com/license
+
+uicolor.title =
+uicolor.preview = Label for checkbox button indicating whether live preview should be enabled
+uicolor.predefined =
+accessibilityHelp.title = Title for accessibility help
+accessibilityHelp.legend.0.name =
+accessibilityHelp.legend.0.items.0.name =
+accessibilityHelp.legend.0.items.0.legend =
+accessibilityHelp.legend.0.items.1.name =
+accessibilityHelp.legend.1.name = The name of second legend (with index 1 though)
+accessibilityHelp.legend.1.items.0.name =
+accessibilityHelp.legend.1.items.0.legend =
+accessibilityHelp.legend.1.items.1.name = The name of legend[1].item[1]
+accessibilityHelp.legend.1.items.1.legend =
+accessibilityHelp.contents =
Index: /CKLangTool/trunk/test/_assets/meta/meta.txt.correct.txt
===================================================================
--- /CKLangTool/trunk/test/_assets/meta/meta.txt.correct.txt (revision 7311)
+++ /CKLangTool/trunk/test/_assets/meta/meta.txt.correct.txt (revision 7311)
@@ -0,0 +1,20 @@
+# Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
+# For licensing, see LICENSE.html or http://ckeditor.com/license
+
+uicolor.title =
+uicolor.preview = Label for checkbox button indicating whether live preview should be enabled
+uicolor.config =
+uicolor.predefined =
+accessibilityHelp.title = Title for accessibility help
+accessibilityHelp.legend.0.name =
+accessibilityHelp.legend.0.items.0.name =
+accessibilityHelp.legend.0.items.0.legend =
+accessibilityHelp.legend.0.items.1.name =
+accessibilityHelp.legend.1.name = The name of second legend (with index 1 though)
+accessibilityHelp.legend.1.items.0.name =
+accessibilityHelp.legend.1.items.0.legend =
+accessibilityHelp.legend.1.items.1.name = The name of legend[1].item[1]
+accessibilityHelp.legend.1.items.1.legend =
+accessibilityHelp.legend.1.items.2.name =
+accessibilityHelp.legend.1.items.2.legend =
+accessibilityHelp.contents =
Index: /CKLangTool/trunk/test/test.js
===================================================================
--- /CKLangTool/trunk/test/test.js (revision 7310)
+++ /CKLangTool/trunk/test/test.js (revision 7311)
@@ -99,5 +99,5 @@
error( "Can't create temp directory: " + tempDir );
- var tests = [ 'gettext', 'gettext/out', 'jprops', 'jprops/out', 'translator', 'translator2' ];
+ var tests = [ 'gettext', 'gettext/out', 'jprops', 'jprops/out', 'translator', 'translator2', 'meta', 'meta/out' ];
for ( var i = 0 ; i < tests.length ; i++ )
@@ -149,5 +149,9 @@
CKLANGTOOL.destinationDir = new File( tmpDir + '/out' );
CKLANGTOOL.templateFile = new File( tmpDir, 'en.js' );
-
+
+ if ( format == 'meta' )
+ {
+ CKLANGTOOL.metaFile = '_assets/meta/meta.txt';
+ }
var dir = new File( '_assets/' + format );
var dirList = dir.list();
@@ -184,4 +188,5 @@
testFormat('gettext');
testFormat('jprops');
+ testFormat('meta');
print( '' );