On 16 ene, 20:59, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > Hi, > > > I have a Menu app that takes data from the database and renders it > > into a template. I was wondering if I can translate the output from > > the database. There are only a few entries. > > Can I add the text that the menu will render that is stored in the db > > and add it to the .po file? > > How can I do it? > > I am assuming that you mean "how can I add the language translations > from the DB to the .po file dynamically?". That's complicated by the > fact that adding to the .po file is not enough -- you will need to > compile the .po file and restart the Django application. Translations > get loaded only once when the application/server process starts up. > > If your menu doesn't change at all, you could just add the > translations to the .po file manually :) > > Otherwise, something simple like the following will allow you to get > dynamic translations: > > In your view that renders the menu, grab the value of > request.LANGUAGE_CODE and fetch your menu items from the DB based on > that language code. Then, send the menu items to your template. You > will need to include LocaleMiddleware for this to work as described > here: > > http://www.djangoproject.com/documentation/i18n/ > > If you're not rendering your menus through a view, let us know how > you're doing it and there's probably a way to use the above solution > with it (middleware, templatetags, ...) > > -Rajesh D
I'm rendering the menu through templatetags, The output is a unordered list (without the first ul) like this: <li> <a href="...">Category 1</a> <ul> <li><a href="...">Subcategory1</a></li> <li><a href="...">Subcategory2</a></li> </ul> </li> so what I need to translate Category 1, Subcategory1... The list is built using a recursive function, and all the texts come from the db. This is the function, I'm sorry it's written in Spanish but I think you can understan what I'm saying def items(bloque, padre): if padre == 0: entradasMenu = bloque.menu_set.filter(padre__isnull = True, visible=True).order_by('orden') else: entradasMenu = bloque.menu_set.filter(padre = padre,visible=True).order_by('orden') salida="" if entradasMenu: for entrada in entradasMenu: (1)----->>> salida += u"\t<li><a href='%s' title='%s'> %s</a>\n" %( entrada.enlace, entrada.nombre, entrada.nombre ) #Si no tiene hijos cierro el li y si no los meto aqui tmp = items (bloque, entrada.id) if tmp !="": salida += u"<ul>%s</ul>" % ( tmp, ) salida += u"</li>" return salida In the line (1) is where the translation should be done. Thank you. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---