最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I localise colorbox? - Stack Overflow

programmeradmin0浏览0评论

I installed Colorbox in my ROR application. But I need localisation. In the script i have:

file images.js.coffee

$(document).ready ->
          $(".group1").colorbox({rel:'group1',
 transition:"none", maxWidth:"85%", maxHeight:"85%",
 current: "{current} <%= t('views.image.of') %> {total}"})

where {current} is current image and {total} are total images.

How to paste data from yml-file (app/config/locales/**.yml)?

I installed Colorbox in my ROR application. But I need localisation. In the script i have:

file images.js.coffee

$(document).ready ->
          $(".group1").colorbox({rel:'group1',
 transition:"none", maxWidth:"85%", maxHeight:"85%",
 current: "{current} <%= t('views.image.of') %> {total}"})

where {current} is current image and {total} are total images.

How to paste data from yml-file (app/config/locales/**.yml)?

Share Improve this question edited Aug 22, 2012 at 11:13 user1466717 asked Aug 22, 2012 at 11:08 user1466717user1466717 7891 gold badge10 silver badges24 bronze badges 1
  • I tried "{current} t('views.image.of') {total}" and "{current}" + t('views.image.of') + "{total}" and "{current} i18n.t('views.image.of') {total}" and "{current}" + i18n.t('views.image.of') + "{total}" – user1466717 Commented Aug 22, 2012 at 11:10
Add a ment  | 

2 Answers 2

Reset to default 7

You are translating a jQuery plugin. Do it within the vendor directory, not in your application locales.

jQuery ColorBox maintains a i18n directory with translations: https://github./jackmoore/colorbox/tree/master/i18n

Example

/*
  jQuery ColorBox language configuration
    language: Spanish (es)
    translated by: migolo
*/
jQuery.extend(jQuery.colorbox.settings, {
    current: "Imagen {current} de {total}",
    previous: "Anterior",
    next: "Siguiente",
    close: "Cerrar",
    xhrError: "Error en la carga del contenido.",
    imgError: "Error en la carga de la imagen."
});

You can download one and include it after colorbox (bonus points if you use git submodules).

Example with Rails >= 3.1

//= require jquery.colorbox
//= require jquery.colorbox-es

I use gem https://github./fnando/i18n-js

It's works!

$(document).ready ->
      $(".group1").colorbox({rel:'group1',
          transition:"none", maxWidth:"85%", maxHeight:"85%",
           current: "{current} <%= I18n.t('views.image.of') %> {total}"})
发布评论

评论列表(0)

  1. 暂无评论