Sphinx docs and Google Translate

200 views
Skip to first unread message

Fredrik Johansson

unread,
May 9, 2008, 5:33:43 AM5/9/08
to sphin...@googlegroups.com
Hi

I notice that some people have tried to view my Sphinx-generated docs
through Google Translate. Looking at the translation from Engligh to
my own native language (Swedish), the text is actually quite readable
(except for the usual quirks like "generators" being translated to
"spisar" (stoves :)), so I think this could be useful for some people,
even to the point that I'd consider linking to machine-translated
versions on the website.

The catch is that Google Translate tries to translate all content in
Python code examples, and this breaks the code completely. So the
question is whether there is some kind of HTML or CSS directive that
can be used to tell Google Translate to skip the code examples? If so,
I think this would be a useful enhancement to Sphinx. Otherwise, I
might try to contact the Google Translate team to suggest such a
feature.

Fredrik

Georg Brandl

unread,
May 14, 2008, 11:42:19 AM5/14/08
to sphin...@googlegroups.com
Fredrik Johansson schrieb:

> Hi
>
> I notice that some people have tried to view my Sphinx-generated docs
> through Google Translate. Looking at the translation from Engligh to
> my own native language (Swedish), the text is actually quite readable
> (except for the usual quirks like "generators" being translated to
> "spisar" (stoves :)), so I think this could be useful for some people,
> even to the point that I'd consider linking to machine-translated
> versions on the website.

That's a nice idea!

> The catch is that Google Translate tries to translate all content in
> Python code examples, and this breaks the code completely. So the
> question is whether there is some kind of HTML or CSS directive that
> can be used to tell Google Translate to skip the code examples? If so,
> I think this would be a useful enhancement to Sphinx. Otherwise, I
> might try to contact the Google Translate team to suggest such a
> feature.

I don't know if Google Translate has such a feature. (IMO it should
certainly exclude e.g. <pre> tags by default.)

If you can find out whether there's some custom attribute or CSS
property that can be set to disable translation, I'll certainly
add a Sphinx setting to output these.

cheers,
Georg

Fred Drake

unread,
May 14, 2008, 5:27:45 PM5/14/08
to sphin...@googlegroups.com
On Wed, May 14, 2008 at 11:42 AM, Georg Brandl <georg....@gmail.com> wrote:
> I don't know if Google Translate has such a feature. (IMO it should
> certainly exclude e.g. <pre> tags by default.)

Why? The fact that programmers use it to render code is
circumstantial; there's nothing about an implied language change in
the HTML specification.

> If you can find out whether there's some custom attribute or CSS
> property that can be set to disable translation, I'll certainly
> add a Sphinx setting to output these.

I tried to see if there's a language code that means "not a
known/translatable language", but couldn't find anything. I suspect
using something like "x-code" (or a more specific "x-python" if a more
specific language is known) might do the trick if Google Translate
handles unknown language codes reasonably.

Ideally, there'd be a way to say "not translatable", I don't know if
lang="" would suffice or not.


-Fred

--
Fred L. Drake, Jr. <fdrake at gmail.com>
"Chaos is the score upon which reality is written." --Henry Miller

Bruno J. M. Melo

unread,
May 14, 2008, 6:47:27 PM5/14/08
to sphin...@googlegroups.com
From Google Translate FAQ (http://www.google.com/intl/en/help/faq_translation.html#donttrans):

What do I do if I don't want my webpage to be translated?

If you prefer not have your page translated by Google Translate, just insert the following meta tag into your HTML file:

<meta name="google" value="notranslate">

Cheers,
--
Bruno J. M. Melo (http://dubita.com/ | brunojm <at> gmail <dot> com)

Fred Drake

unread,
May 14, 2008, 7:14:45 PM5/14/08
to sphin...@googlegroups.com
On Wed, May 14, 2008 at 6:47 PM, Bruno J. M. Melo <bru...@gmail.com> wrote:
> If you prefer not have your page translated by Google Translate, just insert
> the following meta tag into your HTML file:
>
> <meta name="google" value="notranslate"> Cheers,

The problem, though, is that we want to be able to affect translation
for *part* of a page (the examples); the rest of the text should still
be translated. (Inline function, method, and class names shouldn't be
translated either.)

Georg Brandl

unread,
May 16, 2008, 9:33:56 AM5/16/08
to sphin...@googlegroups.com
Fred Drake schrieb:

> On Wed, May 14, 2008 at 11:42 AM, Georg Brandl <georg....@gmail.com> wrote:
>> I don't know if Google Translate has such a feature. (IMO it should
>> certainly exclude e.g. <pre> tags by default.)
>
> Why? The fact that programmers use it to render code is
> circumstantial; there's nothing about an implied language change in
> the HTML specification.
>
>> If you can find out whether there's some custom attribute or CSS
>> property that can be set to disable translation, I'll certainly
>> add a Sphinx setting to output these.
>
> I tried to see if there's a language code that means "not a
> known/translatable language", but couldn't find anything. I suspect
> using something like "x-code" (or a more specific "x-python" if a more
> specific language is known) might do the trick if Google Translate
> handles unknown language codes reasonably.
>
> Ideally, there'd be a way to say "not translatable", I don't know if
> lang="" would suffice or not.

Okay, I will experiment with different "lang" settings and see if it makes
a difference.

Georg

Georg Brandl

unread,
May 24, 2008, 1:03:25 PM5/24/08
to sphin...@googlegroups.com
Fredrik Johansson schrieb:

I have now tried several "lang" attributes for pre tags, and it does not
seem like Google Translate takes these as a hint whether to translate
or not.

I guess it will be best if you contact the Translate team about that.

cheers,
Georg

Reply all
Reply to author
Forward
0 new messages