Language support for TinyMCE

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Language support for TinyMCE

Kirk Steffensen
WP Hackers,

Below is a proposed change to wp-includes/js/tinymce/tiny_mce_gzip.php to
restore native TinyMCE language support.  Before I post this to Trac as an
enhancement, I wanted to make sure that I'm not missing something.  If no one
points out a logic error or a better way to build the mousetrap, I'll make a
patch and post it to Trac.

===BACKGROUND===

I was happy to finally find documentation on the TinyMCE filters at
http://codex.wordpress.org/Plugin_API#Rich_Editor_Filters - I even added some
example functions to the codex once I worked them out for the WPG2 plugin.

However, I haven't been able to figure out a way to restore the native TinyMCE
language support.  It looks like tiny_mce_gzip.php will apply
wp_translate_tinymce_lang, which in turn applies the overall WordPress mo and
po files.  So, if there is a phrase that's in the master mo and po, you're good
to go.  But since the TinyMCE plugins are not WordPress plugins, there is no
obvious way to make and apply a mo and po file for them.

The only language files that ship with the WP instance of TinyMCE are the en.js
files.  The only phrases that I could find supported in the overall WP mo and
po files are in support of the TinyMCE WP help popup.  If you want to install
the other lang files from TinyMCE, e.g., de.js or zh_TW.js, it appears you're
out of luck.

===PROPOSED CHANGE===

I propose changing the following code in tiny_mce_gzip.php to allow loading
TinyMCE lang files, if they exist.  The code change finds WP's locale setting
(xx), and then checks to see if there are corresponding xx.js files for core
TinyMCE, the active TinyMCE theme, and any plugins.  If there are not
corresponding xx.js files, then the default en.js file is loaded.  After that,
the the wp_translate_tinymce_lang function is still called.

Existing Code:
[code]
        // Load theme, language pack and theme language packs
        $theme = apply_filters('mce_theme', 'advanced');

        echo wp_compact_tinymce_js(file_get_contents(realpath("themes/" . $theme .
"/editor_template.js")));

        echo wp_translate_tinymce_lang(file_get_contents(realpath("themes/" . $theme .
"/langs/en.js")));

        echo wp_translate_tinymce_lang(file_get_contents(realpath("langs/en.js")));

        // Load all plugins and their language packs
        $plugins = apply_filters('mce_plugins', array('wordpress', 'autosave',
'wphelp'));

        foreach ($plugins as $plugin) {
                $pluginFile = realpath("plugins/" . $plugin . "/editor_plugin.js");
                $languageFile = realpath("plugins/" . $plugin . "/langs/en.js");

[/code]

Proposed New Code:
[code]
        // Load theme, language pack and theme language packs
        $theme = apply_filters('mce_theme', 'advanced');

        echo wp_compact_tinymce_js(file_get_contents(realpath("themes/" . $theme .
"/editor_template.js")));

        // Get the WordPress locale
        $locale = get_locale();

        $themeLanguageFile = realpath("themes/" . $theme . "/langs/" . $locale .
".js");

        if (!file_exists($themeLanguageFile))
                $themeLanguageFile = realpath("themes/" . $theme . "/langs/en.js");
        echo wp_translate_tinymce_lang(file_get_contents($themeLanguageFile));

        $tinymceLanguageFile = realpath("langs/" . $locale . ".js");

        if (!file_exists($tinymceLanguageFile))
                $tinymceLanguageFile = realpath("langs/en.js");
        echo wp_translate_tinymce_lang(file_get_contents($tinymceLanguageFile));

        // Load all plugins and their language packs
        $plugins = apply_filters('mce_plugins', array('wordpress', 'autosave',
'wphelp'));

        foreach ($plugins as $plugin) {
                $pluginFile = realpath("plugins/" . $plugin . "/editor_plugin.js");
                $languageFile = realpath("plugins/" . $plugin . "/langs/" . $locale . ".js");
                if (!file_exists($languageFile))
                        $languageFile = realpath("plugins/" . $plugin . "/langs/en.js");
[/code]

We've tested this quite a bit in the WPG2 community and it works well.  Stephen
Ju of http://www.ju-ju.com/ did most of the development on this and has
successfully implemented a zh_TW.js file for my TinyMCE plugin
(http://g2image.steffensenfamily.com) and has restored zh_TW.js for the both
core TinyMCE and the advanced theme.

If we're missing an easier way to do this, or someone else has already hacked a
better hack, please let us know.  If not, I'll put together a patch and submit
it to Trac.

Thanks,
Kirk

Kirk Steffensen
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Language support for TinyMCE

Andy Skelton
On 2/16/06, Kirk Steffensen <[hidden email]> wrote:
> I propose changing the following code in tiny_mce_gzip.php to allow loading
> TinyMCE lang files, if they exist.  The code change finds WP's locale setting
> (xx), and then checks to see if there are corresponding xx.js files for core
> TinyMCE, the active TinyMCE theme, and any plugins.  If there are not
> corresponding xx.js files, then the default en.js file is loaded.  After that,
> the the wp_translate_tinymce_lang function is still called.

Looks great to me!

Andy
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Language support for TinyMCE

Stefano-10
In reply to this post by Kirk Steffensen
Il Thu, 16 Feb 2006 13:27:42 -0500, Kirk Steffensen
<[hidden email]> scrive:

>WP Hackers,
>
>Below is a proposed change to wp-includes/js/tinymce/tiny_mce_gzip.php to
>restore native TinyMCE language support.  Before I post this to Trac as an
>enhancement, I wanted to make sure that I'm not missing something.  If no one
>points out a logic error or a better way to build the mousetrap, I'll make a
>patch and post it to Trac.

+1 for me.

I think you could submit the patch to trac so bug gardeners will check
it and then Ryan will do too.

--

Stefano Aglietti - StallonIt on IRCnet - ICQ#: 2078431
Email: [hidden email] [hidden email]
Sites: http://www.40annibuttati.it (personal blog)
       http://www.wordpress-it.it (WordPress Italia)
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Language support for TinyMCE

Kirk Steffensen
Thanks.  It's posted on Trac as ticket #2476.
http://trac.wordpress.org/ticket/2476

Quoting Stefano <[hidden email]>:
> +1 for me.
>
> I think you could submit the patch to trac so bug gardeners will check
> it and then Ryan will do too.


_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Language support for TinyMCE

Kimmo Suominen-3
On Fri, Feb 17, 2006 at 06:13:03PM -0500, Kirk Steffensen wrote:
> Thanks.  It's posted on Trac as ticket #2476.
> http://trac.wordpress.org/ticket/2476

Thank you, Kirk!

Cheers,
+ Kimmo
--
<A HREF="http://kimmo.suominen.com/">Kimmo Suominen</A>

_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Language support for TinyMCE

Stefano-10
In reply to this post by Kirk Steffensen
Il Fri, 17 Feb 2006 18:13:03 -0500, Kirk Steffensen
<[hidden email]> scrive:

>Thanks.  It's posted on Trac as ticket #2476.
>http://trac.wordpress.org/ticket/2476
>
>Quoting Stefano <[hidden email]>:
>> +1 for me.
>>
>> I think you could submit the patch to trac so bug gardeners will check
>> it and then Ryan will do too.

Thanks for your work

--

Stefano Aglietti - StallonIt on IRCnet - ICQ#: 2078431
Email: [hidden email] [hidden email]
Sites: http://www.40annibuttati.it (personal blog)
       http://www.wordpress-it.it (WordPress Italia)
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers