Translating with HTML
Closed this issue · 14 comments
Thanks for the translator script. I think the issue is more with Google than with your script. if html is translated, ends up as </ li> which isn't right. So one can't translate an article that has paragraphs and html elements without it breaking. So my question is more of a tip:
Can I possibly translate html without damaging the html codes? If yes, how? Any suggestion is appreciated.
Yes, this is a problem with Google Translate itself.
I guess you can write a regex (or just str_replace
) to replace < /
with </
(without space). But anyways, do not depend on "hacks" like that.
You should do it with regex as the space is after /
.
Any examples? It really misses up everything...
On Thu, May 14, 2015 at 8:03 PM, Levan Velijanashvili <
notifications@github.com> wrote:
You should do it with regex as the space is after /.
—
Reply to this email directly or view it on GitHub
#23 (comment)
.
Steward Godwin Jornsen
+234.803.9468.290
StewardXpress Nigeria Limited
www.stewardxpress.com
In His Name Bible Church
www.inhisnamebiblechurch.com http://www.ihnbc.com
This mail should only be used for the purpose of which it was sent and by
the receiver of this mail only. We guarantee that this mail is sent free of
all viruses or spyware. You are advised to scan attachments before opening.
StewardXpress/In His Name Bible Church is not responsible for how you used
the provided data.
$result = $t->translate('html string here');
$result_with_correct_html = preg_replace('/\/\s/', '/', $result);
That's it.
Thank you very much. I shall give that a try. If that works great, you
could as well extend the class to have that html return object. That could
be cool, don't you think?
Thanks again.
On Wed, May 20, 2015 at 11:00 AM, Levan Velijanashvili <
notifications@github.com> wrote:
$result = $t->translate('html string here');$result_with_correct_html = preg_replace('//\s/', '/', $result);
That's it.
—
Reply to this email directly or view it on GitHub
#23 (comment)
.
Steward Godwin Jornsen
+234.803.9468.290
StewardXpress Nigeria Limited
www.stewardxpress.com
In His Name Bible Church
www.inhisnamebiblechurch.com http://www.ihnbc.com
This mail should only be used for the purpose of which it was sent and by
the receiver of this mail only. We guarantee that this mail is sent free of
all viruses or spyware. You are advised to scan attachments before opening.
StewardXpress/In His Name Bible Church is not responsible for how you used
the provided data.
I really appreciate your idea, but I don't think so. This package has a very simple API - just three methods and that's it. This is not intended to translate HTML strings. If so, then why not add JSON or XML support? It will lead to very impure code. Bringing back HTML tags is one simple regex (noted above). It's not worth adding extra functionality for that. Plus, I'm not sure this regex will fix all problems with translated HTML.
P.S I won't close this issue for now. Let it be open for further public discussions.
The official paid API has format
attribute where you can set that translated text is HTML.
So if we could find any way* to make it work with HTML strings without damaging tags and avoiding usage of extra "hacky" regexes, it would be really cool.
* - Maybe it can be achieved using some attribute in URL string. The actual translate.google.com doesn't have option to set type to HTML, so I'm not sure we can find an easy solution for this
Thanks,
No point anyway. Google sometimes translates the names of classes and Tag
ID which does seriously scramble website functionality.
Steward
On Thu, May 21, 2015 at 1:01 AM, Levan Velijanashvili <
notifications@github.com> wrote:
The official paid API has format attribute
https://cloud.google.com/translate/v2/using_rest#query-params where you
can set that translated text is HTML.So if we could find any way* to make it work with HTML strings without
damaging tags and avoiding usage of extra "hacky" regexes, it would be
really cool.* - Maybe it can be achieved using some attribute in URL string
.google-translate-php/src/Stichoza/GoogleTranslate/TranslateClient.php
Lines 55 to 68 in b11ae50
—
Reply to this email directly or view it on GitHub
#23 (comment)
.
Steward Godwin Jornsen
+234.803.9468.290
StewardXpress Nigeria Limited
www.stewardxpress.com
In His Name Bible Church
www.inhisnamebiblechurch.com http://www.ihnbc.com
This mail should only be used for the purpose of which it was sent and by
the receiver of this mail only. We guarantee that this mail is sent free of
all viruses or spyware. You are advised to scan attachments before opening.
StewardXpress/In His Name Bible Church is not responsible for how you used
the provided data.
That's exactly what I mean "without damaging tags". Yea, I think there's no way to translate HTML using this service url.
Can you make autoload versions ?. There i using hosting. Not supported for installing new php library
The official API has way better support for html tags. When reverse engineering the current inline translation of Google Chrome, these results are also very good (and with correct html tags).
I've extracted the following parameters, Google Chrome currently uses:
Can anybody check if some parameters are missing in this library?
Please help me regex replace: class = "row" => class="row"
bro you can use this to translate your html database data to any language using this package.
just use like this---- First decode the html code.. then use inside this package translate function.
{!! \Stichoza\GoogleTranslate\TranslateClient::translate( Session::get('s_lang'), Session::get('t_lang'), html_entity_decode(str_limit($n->body,500) ) ) !!}
The official paid API has
format
attribute where you can set that translated text is HTML.
the paid API also allows <div class="notranslate">...</div>
to disable translation for specific terms
So if we could find any way* to make it work with HTML strings without damaging tags and avoiding usage of extra "hacky" regexes, it would be really cool.
* - Maybe it can be achieved using some attribute in URL string. The actual translate.google.com doesn't have option to set type to HTML, so I'm not sure we can find an easy solution for this
yes, it was not easy ^^ but i got it working in my translate.js script
also see my post in Prohibit the translation of pieces of text in Google Translate