On Sat, Feb 16, 2008 at 08:33:59AM +0100, Lionel Elie Mamane wrote:
> On Thu, Jan 31, 2008 at 04:18:38PM +0200, Nikolay Bachiyski wrote:

>> However, I like the idea of specially-formatted comments -- something like:

>> wp_die(/*WP_I18N_NOWPCONF*/"There doesn't seem to be a
>> <code>wp-config.php</code> file..."/*/WP_I18N_NOWPCONF*/");

>> Thus we can put these strings into the mo file and replace them on the
>> localized package build stage.

> I'm starting a shell script "proof of concept" implementation after
> breakfast.

Herewith attached is:

 - a (partial) patch for wordpress 2.3.3
 - a tarball with my static-l10n code, and example .po files for
   English and French, with some.

for a first draft of what it would look like. Please let me know what
you think; in particular, if I finish it and polish it up, is it good
for commit in Wordpress (I'll send a patch against trunk in that case,
obviously). Here is how it is used:

tar xfz i18n-tools-0.0.1.tar.gz /some/place
/some/place/compile-static-i18n
/some/place/translate-static /path/to/wordpress/tree LANGUAGE_CODE

This will translate the static strings between /*WP_I18N_START_FOO*/
and /*WP_I18N_END_FOO*/ in files where they occur. The list of values
for FOO and the list of files is static in the translate-static
script.

It requires sed, a POSIX-compliant /bin/sh and GNU gettext installed.

The suggested way for a programmer to change the English string is to
change it in en.po and run translate-static. And then, warn all
translators. Or we can drop en.po and developers can have the fun of
chasing every occurrence of the string and change it the same way
everywhere; they'd still have to warn translators. See also below.

Where shall we place the contents of the said tarball? Directly as a
subdirectory "l10n-tools" of wordpress? In a separate SVN repository
(maybe where I would commit directly), e.g. in the wordpress-i18n
repository, under tools?

Bugs and problems:

 - The translator sees the FOO part of the placeholder (e.g. NOWPCONF)
   as msgid instead of the English version of the string; he has to
   look up in the code or in en.po what the English version of that
   string is.

   As a consequence, if a programmer changes the English version of
   the string in the code, there is no automatic way for the
   translators to be notified (the string does not become "fuzzy" in
   gettext terms).

   Fixing that is a bit problematic; to look up the English string
   instead of the placeholder, I'd have to interpret PHP strings,
   something I'm not very eager to code up in shell...

 - The implementation does not support multi-line strings and it is a
   bit delicate to add that support. Mainly include/wp-db.php contains
   multi-line strings. Would it be OK to change them to single-line
   strings, with \n escapes for newlines?

-- 
Lionel
diff --git a/wp-admin/install.php b/wp-admin/install.php
index 6f4d7e3..360819a 100644
--- a/wp-admin/install.php
+++ b/wp-admin/install.php
@@ -3,7 +3,7 @@ define('WP_INSTALLING', true);
 if (!file_exists('../wp-config.php')) {
   require_once('../wp-includes/compat.php');
   require_once('../wp-includes/functions.php');
-  wp_die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can <a href='setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.", "WordPress &rsaquo; Error");
+  wp_die(/*WP_I18N_START_NOWPCONF*/ "There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can <a href='setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file." /*WP_I18N_END_NOWPCONF*/, "WordPress &rsaquo; Error");
 }
 
 require_once('../wp-config.php');
diff --git a/wp-admin/upgrade.php b/wp-admin/upgrade.php
index 1758d4c..deb2e73 100644
--- a/wp-admin/upgrade.php
+++ b/wp-admin/upgrade.php
@@ -1,7 +1,7 @@
 <?php
 define('WP_INSTALLING', true);
 if (!file_exists('../wp-config.php'))
-	die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Installing_WordPress#Step_3:_Set_up_wp-config.php'>We got it</a>. You can <a href='setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.");
+	die(/*WP_I18N_START_NOWPCONF*/ "There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Installing_WordPress#Step_3:_Set_up_wp-config.php'>We got it</a>. You can <a href='setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file." /*WP_I18N_END_NOWPCONF*/);
 
 require('../wp-config.php');
 timer_start();
diff --git a/wp-blog-header.php b/wp-blog-header.php
index 00d3ccd..95da950 100644
--- a/wp-blog-header.php
+++ b/wp-blog-header.php
@@ -8,7 +8,7 @@ if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) {
 	require_once( dirname(__FILE__) . '/wp-includes/classes.php');
 	require_once( dirname(__FILE__) . '/wp-includes/functions.php');
 	require_once( dirname(__FILE__) . '/wp-includes/plugin.php');
-	wp_die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can <a href='{$path}setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.", "WordPress &rsaquo; Error");
+	wp_die(/*WP_I18N_START_NOWPCONF*/ "There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Installing_WordPress#Step_3:_Set_up_wp-config.php'>We got it</a>. You can <a href='setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file." /*WP_I18N_END_NOWPCONF*/, "WordPress &rsaquo; Error");
 }
 
 $wp_did_header = true;
diff --git a/wp-settings.php b/wp-settings.php
index a930ddd..314425f 100644
--- a/wp-settings.php
+++ b/wp-settings.php
@@ -5,7 +5,7 @@ function wp_unregister_GLOBALS() {
 		return;
 
 	if ( isset($_REQUEST['GLOBALS']) )
-		die('GLOBALS overwrite attempt detected');
+		die(/*WP_I18N_START_GLOBALS_OVERWRITE*/ 'GLOBALS overwrite attempt detected' /*WP_I18N_END_GLOBALS_OVERWRITE*/);
 
 	// Variables that shouldn't be unset
 	$noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');
@@ -67,11 +67,11 @@ if ( empty($PHP_SELF) )
 	$_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
 
 if ( version_compare( '4.2', phpversion(), '>' ) ) {
-	die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.2.' );
+	die(sprintf(/*WP_I18N_START_PHP_VER_42*/ 'Your server is running PHP version %s but WordPress requires at least 4.2.' /*WP_I18N_END_PHP_VER_42*/, phpversion()));
 }
 
 if ( !extension_loaded('mysql') && !file_exists(ABSPATH . 'wp-content/db.php') )
-	die( 'Your PHP installation appears to be missing the MySQL which is required for WordPress.' );
+     die(/*WP_I18N_START_NO_MYSQL*/ 'Your PHP installation appears to be missing the MySQL extension, which is required for WordPress.' /*WP_I18N_END_NO_MYSQL*/);
 
 function timer_start() {
 	global $timestart;
@@ -129,7 +129,7 @@ if ( !empty($wpdb->error) )
 $wpdb->prefix = $table_prefix;
 
 if ( preg_match('|[^a-z0-9_]|i', $wpdb->prefix) && !file_exists(ABSPATH . 'wp-content/db.php') )
-	wp_die("<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.");
+        wp_die(/*WP_I18N_START_BAD_TABLE_PREFIX*/ "<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores." /*WP_I18N_END_BAD_TABLE_PREFIX*/);
 
 // Table names
 $wpdb->posts          = $wpdb->prefix . 'posts';

Attachment: wordpress-static-l10n.tar.gz
Description: Binary data

Reply via email to