Git Product home page Git Product logo

Comments (21)

deschler avatar deschler commented on June 14, 2024

From eschler on May 01, 2010 21:35:33
Yes that's a nice idea. And coincidentally i received some code by a user this week
which connects to the google translation api.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From [email protected] on May 01, 2010 22:58:51
Great! thnx)

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From jaap%[email protected] on June 19, 2010 18:30:42
I've written a bit of javascript that adds a suggest link to all non-default translation fields. It works the same way as the rosetta suggest link works.

In order to find translatable fields with jQuery I did have to alter TranslationAdminBase.patch_translation_field. It now adds CSS classes to the translatable field's widget.

To see it in action you'll have to add a Media inner class to your translatable admin class.

class FooAdmin(TranslationAdmin):
class Media:
js = (
'http://www.google.com/jsapi',
'/static/js/google_translate.js',
)

Note that the JS depends on Django 1.2 (it looks for django.jQuery)

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From jaap%[email protected] on June 20, 2010 14:28:17
Here's a new version of the javascript. This time newlines are kept intact (when suggesting content from a textarea for example).

The code now also only activates on the change form.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From eschler on June 25, 2010 18:42:04
Excellent job! I'm glad you did all the hard JavaScript coding. :-) Seems to work like a charm.

As a usability improvement, i think it would be nice if the suggest link reappears when the field is cleared, or the link turns into a clear link once you have clicked it. I'm not sure what's better.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From eschler on June 25, 2010 19:09:10
Found a bug. If the field accepts blank values (blank=True), all its translation fields get a suggest link. The suggestion fails and the link is turned into "...".

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From eschler on July 08, 2010 09:58:39
Committed your patch which adds the css classes. This can be useful for other admin modification as well.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From [email protected] on July 14, 2010 16:16:42

If the field accepts blank values (blank=True), all its translation fields get a suggest link.

Default language fields that are optional don't get the correct CSS class. I've added a patch that resolves that.

I'll look into the other things you've mentioned.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From [email protected] on July 14, 2010 17:41:05
Here's a new version with the flowing things changed:

  • Make the suggest link reappear when the field gets cleared.
  • Handle translation errors by just showing the suggest link again.
  • Look for django.jQuery || jQuery || $ to find jQuery

I'd like to suggest that the JS gets distributed with modeltranslation in the following location:

modeltranslation/media/modeltranslation/js/google_translate.js

This way it can be served by django-staticfiles (http://pypi.python.org/pypi/django-staticfiles/).

Again, to see it in action do something like this:

class FooAdmin(TranslationAdmin):
class Media:
js = (
'http://www.google.com/jsapi',
'/static/modeltranslation/js/google_translate.js',
)

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From [email protected] on July 14, 2010 17:53:30
Here's a patch for MANIFEST.in to include all files in modeltranslation/media/

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From jaap%[email protected] on July 15, 2010 11:13:08
Small issue... when using a tinymce field a 'suggest' link appears. Clicking it doesn't set the translated value in the TinyMCE instance.

I'm not sure how to detect when a textarea will become a tinymce field.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From eschler on July 18, 2010 22:52:31
I would first try to update the field normally and in case it fails, check if there's a tinymce widget and try to update this field. Only if both fails, redisplay the suggest link. What do you think?

Agreed regarding the location.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From [email protected] on July 19, 2010 22:39:09
This could be useful if it could be used in the listview too.
(with list_editable)

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From jaap%[email protected] on August 03, 2010 13:56:08
@ eschler, It's too hard to find out if something is a tinymce widget or not... besides that I don't really want to add tinymce specific code.

@ulvinge, Making this work for listview might be interesting, but is something I'm not sure how to do properly. The main change page is properly suited for this as it (almost) guarantees that all translatable fields are there.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From jaap%[email protected] on August 03, 2010 14:00:42
This version of google_translate.js waits a bit longer before adding the translation links (window.load). In my case this fixes the problem of suggest link for tinymce widgets. When the tinymce fields are fully initialized the textareas are hidden and the logic that adds the link won't kick in...

Could you apply the patches I added in comment 9, comment 11 and this js file to django-modeltranslation's SVN? It's easier to work on this stuff when it's in SVN.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From eschler on September 06, 2010 08:45:17
I don't get a suggest link when using it in conjunction with tabbed translation fields. It just fails silently, for both, char and text fields.

class MyTranslationAdmin(TranslationAdmin):
class Media:
js = (
'/media/cms/js/force_jquery.js',
'/media/cms/js/jquery/ui/minified/jquery.ui.core.min.js',
'/media/cms/js/jquery/ui/minified/jquery.ui.widget.min.js',
'/media/cms/js/jquery/ui/minified/jquery.ui.tabs.min.js',
'/media/cms/modeltranslation/js/tabbed_translation_fields.js',
'http://www.google.com/jsapi',
'/media/cms/modeltranslation/js/google_translate.js',
)

When the tabs related includes are removed, it works.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From [email protected] on October 27, 2010 19:07:56
I'm just learning git and couldn't find how to make patch så heres a psuedo one:

My changes:
@7

  • var jQuery = django.jQuery || jQuery || $;
  • var jQuery = jQuery || $;

There is no such thing as djanog.jQuery, and it removes an extra error message.

@66

  •                            default_translation.lang,
    
  •                            "", //default_translation.lang, //now we autodetect the language
    

Necessary in my bilingual development environment.

@30

  •        var translation_fields = $('.modeltranslation').filter('input[type=text]:visible, textarea:visible'),
    
  •        var translation_fields = $('.modeltranslation'); //.filter('input[type=text]:visible, textarea:visible'),
    

If the textarea is in an collapsible form element, then it didn't work before. Now it works, and I don't have any problems with it (yet).

I consider this somewhat ugly, but it works very well for my needs.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From [email protected] on November 25, 2010 19:55:46
I took google_translate.js from the Comment #10 and had implemented normal TinyMCE support. See my version in the attach.

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

From jaap%[email protected] on April 05, 2011 14:18:52
@kottena... The TinyMCE support works great (only today I finally had to build a multilingual site again :))

@ulvi... django.jQuery should be there in Django admin >= 1.2, not really sure about the other changes.

from django-modeltranslation.

jaap3 avatar jaap3 commented on June 14, 2024

I don't think the script I originally provided will still work, Google's translation API is now a paid service :(

from django-modeltranslation.

deschler avatar deschler commented on June 14, 2024

Too bad, i planned to (finally!) include it 0.5. So unless there is an alternative i close the issue.

from django-modeltranslation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.