javascript i18n wip
This commit is contained in:
parent
7089782ba1
commit
3078156dbb
22 changed files with 410 additions and 1 deletions
13
app/controllers/localize_controller.rb
Normal file
13
app/controllers/localize_controller.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class LocalizeController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
|
||||
include LocalizeHelper
|
||||
|
||||
def show
|
||||
if current_user
|
||||
render :json => localize current_user.language
|
||||
else
|
||||
redirect_to aspects_path
|
||||
end
|
||||
end
|
||||
end
|
||||
8
app/helpers/localize_helper.rb
Normal file
8
app/helpers/localize_helper.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
module LocalizeHelper
|
||||
def localize language
|
||||
yml_path = File.join(Rails.root, "config/locales/diaspora/", "#{language}.yml")
|
||||
yaml = YAML::load IO.read(yml_path)
|
||||
|
||||
yaml[language]["javascripts"]
|
||||
end
|
||||
end
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
- content_for :head do
|
||||
= include_javascripts :home
|
||||
:javascript
|
||||
Diaspora.widgets.i18n.loadLocale(#{localize(current_user.language).to_json}, "#{current_user.language}");
|
||||
|
||||
.span-15.append-2
|
||||
= render 'aspects/no_contacts_message', :aspect => @aspect, :contact_count => @contacts.count
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ javascripts:
|
|||
- public/javascripts/diaspora.js
|
||||
- public/javascripts/widgets/alert.js
|
||||
- public/javascripts/widgets/embedder.js
|
||||
|
||||
- public/javascripts/widgets/i18n.js
|
||||
- public/javascripts/widgets/timeago.js
|
||||
mobile:
|
||||
- public/javascripts/vendor/jquery144.min.js
|
||||
- public/javascripts/custom-mobile-scripting.js
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ da:
|
|||
no_person_constructed: "Ingen person kunne konstrueres fra dette hcard."
|
||||
not_enabled: "det ser ikke ud til at webfinger er aktiveret på %{account}s domæne"
|
||||
xrd_fetch_failed: "der opstod en fejl i forbindelse med hentning af xrd fra kontoen %{account}"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: "for"
|
||||
prefixFromNow: "om"
|
||||
suffixAgo: "siden"
|
||||
suffixFromNow: ""
|
||||
seconds: "mindre end et minut"
|
||||
minute: "ca. et minut"
|
||||
minutes: "%d minutter"
|
||||
hour: "ca. en time"
|
||||
hours: "ca. %d timer"
|
||||
day: "en dag"
|
||||
days: "%d dage"
|
||||
month: "ca. en måned"
|
||||
months: "%d måneder"
|
||||
year: "ca. et år"
|
||||
years: "%d år"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ de:
|
|||
no_person_constructed: "Konnte keine Person aus dieser hcard erstellen."
|
||||
not_enabled: "Webfinger scheint nicht für den Server von %{account} verfügbar zu sein."
|
||||
xrd_fetch_failed: "Die XRD-Datei von %{account} konnte nicht heruntergeladen werden"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: "vor"
|
||||
prefixFromNow: "in"
|
||||
suffixAgo: ""
|
||||
suffixFromNow: ""
|
||||
seconds: "wenigen Sekunden"
|
||||
minute: "etwa einer Minute"
|
||||
minutes: "%d Minuten"
|
||||
hour: "etwa einer Stunde"
|
||||
hours: "%d Stunden"
|
||||
day: "etwa einem Tag"
|
||||
days: "%d Tagen"
|
||||
month: "etwa einem Monat"
|
||||
months: "%d Monaten"
|
||||
year: "etwa einem Jahr"
|
||||
years: "%d Jahren"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ el:
|
|||
no_person_constructed: "No person could be constructed from this hcard."
|
||||
not_enabled: "webfinger does not seem to be enabled for %{account}'s host"
|
||||
xrd_fetch_failed: "there was an error getting the xrd from account %{account}"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: "πριν"
|
||||
prefixFromNow: "σε"
|
||||
suffixAgo: ""
|
||||
suffixFromNow: ""
|
||||
seconds: "λιγότερο από ένα λεπτό"
|
||||
minute: "περίπου ένα λεπτό"
|
||||
minutes: "%d λεπτά"
|
||||
hour: "περίπου μία ώρα"
|
||||
hours: "περίπου %d ώρες"
|
||||
day: "μία μέρα"
|
||||
days: "%d μέρες"
|
||||
month: "περίπου ένα μήνα"
|
||||
months: "%d μήνες"
|
||||
year: "περίπου ένα χρόνο"
|
||||
years: "%d χρόνια"
|
||||
|
|
|
|||
|
|
@ -498,3 +498,5 @@ en:
|
|||
pagination:
|
||||
next: "Next"
|
||||
previous: "Previous"
|
||||
javascripts:
|
||||
confirm_dialog: "Are you sure?"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ es:
|
|||
no_person_constructed: "No person could be constructed from this hcard."
|
||||
not_enabled: "el webfinger parece no estar habilitado para el host de %{account}"
|
||||
xrd_fetch_failed: "hubo un error al recibir el xrd desde la cuenta %{account}"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: "hace"
|
||||
prefixFromNow: "dentro de"
|
||||
suffixAgo: ""
|
||||
suffixFromNow: ""
|
||||
seconds: "menos de un minuto"
|
||||
minute: "un minuto"
|
||||
minutes: "unos %d minutos"
|
||||
hour: "una hora"
|
||||
hours: "%d horas"
|
||||
day: "un día"
|
||||
days: "%d días"
|
||||
month: "un mes"
|
||||
months: "%d meses"
|
||||
year: "un año"
|
||||
years: "%d años"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ fr:
|
|||
no_person_constructed: "Cette hcard semble être invalide."
|
||||
not_enabled: "webfinger ne semble pas être activé sur l'hôte de %{account}'s"
|
||||
xrd_fetch_failed: "une erreur est survenue lors de la récupération du xrd du compte %{account}"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: "il y a"
|
||||
prefixFromNow: "d'ici"
|
||||
suffixAgo: ""
|
||||
suffixFromNow: ""
|
||||
seconds: "moins d'une minute"
|
||||
minute: "environ une minute"
|
||||
minutes: "environ %d minutes"
|
||||
hour: "environ une heure"
|
||||
hours: "environ %d heures"
|
||||
day: "environ un jour"
|
||||
days: "environ %d jours"
|
||||
month: "environ un mois"
|
||||
months: "environ %d mois"
|
||||
year: "un an"
|
||||
years: "%d ans"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ he:
|
|||
no_person_constructed: "לא ניתן להרכיב איש קשר מ־hcard זה."
|
||||
not_enabled: "נראה כי webfinger אינו פעיל עבור המארח של %{account}"
|
||||
xrd_fetch_failed: "אירעה שגיאה בקבלת ה־xrd מהחשבון %{account}"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: "לפני"
|
||||
prefixFromNow: "מעכשיו"
|
||||
suffixAgo: ""
|
||||
suffixFromNow: ""
|
||||
seconds: "פחות מדקה"
|
||||
minute: "דקה"
|
||||
minutes: "%d דקות"
|
||||
hour: "שעה"
|
||||
hours: "%d שעות"
|
||||
day: "יום"
|
||||
days: "%d ימים"
|
||||
month: "חודש"
|
||||
months: "%d חודשים"
|
||||
year: "שנה"
|
||||
years: "%d שנים"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ hu:
|
|||
no_person_constructed: "Ebből a hCard névjegyből nem lehet személyt létrehozni."
|
||||
not_enabled: "a webfinger nincs engedélyezve %{account} kiszolgálóján"
|
||||
xrd_fetch_failed: "%{account} fiókjából nem sikerült az XRD kiolvasása"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: ""
|
||||
prefixFromNow: ""
|
||||
suffixAgo: ""
|
||||
suffixFromNow: ""
|
||||
seconds: "kevesebb mint egy perce"
|
||||
minute: "körülbelül egy perce"
|
||||
minutes: "%d perce"
|
||||
hour: "körülbelül egy órája"
|
||||
hours: "körülbelül %d órája"
|
||||
day: "körülbelül egy napja"
|
||||
days: "%d napja"
|
||||
month: "körülbelül egy hónapja"
|
||||
months: "%d hónapja"
|
||||
year: "körülbelül egy éve"
|
||||
years: "%d éve"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ id:
|
|||
no_person_constructed: "No person could be constructed from this hcard."
|
||||
not_enabled: "webfinger does not seem to be enabled for %{account}'s host"
|
||||
xrd_fetch_failed: "there was an error getting the xrd from account %{account}"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: ""
|
||||
prefixFromNow: ""
|
||||
suffixAgo: "yang lalu"
|
||||
suffixFromNow: "dari sekarang"
|
||||
seconds: "kurang dari semenit"
|
||||
minute: "sekitar satu menit"
|
||||
minutes: "%d menit"
|
||||
hour: "sekitar sejam"
|
||||
hours: "sekitar %d jam"
|
||||
day: "sehari"
|
||||
days: "%d hari"
|
||||
month: "sekitar sebulan"
|
||||
months: "%d tahun"
|
||||
year: "sekitar setahun"
|
||||
years: "%d tahun"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ it:
|
|||
no_person_constructed: "Questa hcard non contiene i dati di una persona."
|
||||
not_enabled: "webfinger non attivo sull'host di %{account}"
|
||||
xrd_fetch_failed: "impossibile recuperare il xrd dall'account %{account}"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: ""
|
||||
prefixFromNow: ""
|
||||
suffixAgo: "fa"
|
||||
suffixFromNow: "da ora"
|
||||
seconds: "meno di un minuto"
|
||||
minute: "circa un minuto"
|
||||
minutes: "%d minuti"
|
||||
hour: "circa un'ora"
|
||||
hours: "circa %d ore"
|
||||
day: "un giorno"
|
||||
days: "%d giorni"
|
||||
month: "circa un mese"
|
||||
months: "%d mesi"
|
||||
year: "circa un anno"
|
||||
years: "%d anni"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ nl:
|
|||
no_person_constructed: "Er kon geen persoon worden gemaakt van deze hcard."
|
||||
not_enabled: "webfinger lijkt niet aan te staan voor %{account}'s provider"
|
||||
xrd_fetch_failed: "er was een probleem bij het verkrijgen van de xrd van het account %{account}"
|
||||
javascript:
|
||||
timeago:
|
||||
prefixAgo: ""
|
||||
prefixFromNow: ""
|
||||
suffixAgo: "geleden"
|
||||
suffixFromNow: "vanaf nu"
|
||||
seconds: "iets minder dan een minute"
|
||||
minute: "ongeveer een minuut"
|
||||
minutes: "%d minuten"
|
||||
hour: "ongeveer een uur"
|
||||
hours: "ongeveer %d uren"
|
||||
day: "een dag"
|
||||
days: "%d dagen"
|
||||
month: "ongeveer een maand"
|
||||
months: "%d maanden"
|
||||
year: "ongeveer een jaar"
|
||||
years: "%d jaar"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ pt-PT:
|
|||
no_person_constructed: "No person could be constructed from this hcard."
|
||||
not_enabled: "webfinger does not seem to be enabled for %{account}'s host"
|
||||
xrd_fetch_failed: "there was an error getting the xrd from account %{account}"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: ""
|
||||
prefixFromNow: ""
|
||||
suffixAgo: "atrás"
|
||||
suffixFromNow: "a partir de agora"
|
||||
seconds: "menos de um minuto"
|
||||
minute: "cerca de um minuto"
|
||||
minutes: "%d minutos"
|
||||
hour: "cerca de uma hora"
|
||||
hours: "cerca de %d horas"
|
||||
day: "um dia"
|
||||
days: "%d dias"
|
||||
month: "cerca de um mês"
|
||||
months: "%d meses"
|
||||
year: "cerca de um ano"
|
||||
years: "%d anos"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ ro:
|
|||
no_person_constructed: "No person could be constructed from this hcard."
|
||||
not_enabled: "webfinger does not seem to be enabled for %{account}'s host"
|
||||
xrd_fetch_failed: "there was an error getting the xrd from account %{account}"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: "acum"
|
||||
prefixFromNow: "in timp de"
|
||||
suffixAgo: ""
|
||||
suffixFromNow: ""
|
||||
seconds: "mai putin de un minut"
|
||||
minute: "un minut"
|
||||
minutes: "%d minute"
|
||||
hour: "o ora"
|
||||
hours: "%d ore"
|
||||
day: "o zi"
|
||||
days: "%d zile"
|
||||
month: "o luna"
|
||||
months: "%d luni"
|
||||
year: "un an"
|
||||
years: "%d ani"
|
||||
|
|
|
|||
|
|
@ -493,3 +493,20 @@ sv:
|
|||
no_person_constructed: "Den här personen kunde inte hittas (hcard-fel)."
|
||||
not_enabled: "Webfinger verkar inte vara påslaget på %{account}'s server"
|
||||
xrd_fetch_failed: "kunde inte hämta xrd-fil från kontot %{account}"
|
||||
javascripts:
|
||||
timeago:
|
||||
prefixAgo: "för"
|
||||
prefixFromNow: "om"
|
||||
suffixAgo: "sedan"
|
||||
suffixFromNow: ""
|
||||
seconds: "mindre än en minut"
|
||||
minute: "ungefär en minut"
|
||||
minutes: "%d minuter"
|
||||
hour: "ungefär en timme"
|
||||
hours: "ungefär %d timmar"
|
||||
day: "en dag"
|
||||
days: "%d dagar"
|
||||
month: "ungefär en månad"
|
||||
months: "%d månader"
|
||||
year: "ungefär ett år"
|
||||
years: "%d år"
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ Diaspora::Application.routes.draw do
|
|||
match 'receive/users/:guid', :to => 'publics#receive'
|
||||
match 'hub', :to => 'publics#hub'
|
||||
|
||||
match 'localize', :to => "localize#show"
|
||||
|
||||
#root
|
||||
root :to => 'home#show'
|
||||
end
|
||||
|
|
|
|||
58
public/javascripts/vendor/jquery.charcount.js
vendored
Normal file
58
public/javascripts/vendor/jquery.charcount.js
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Character Count Plugin - jQuery plugin
|
||||
* Dynamic character count for text areas and input fields
|
||||
* written by Alen Grakalic
|
||||
* http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas
|
||||
*
|
||||
* Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
|
||||
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
||||
* and GPL (GPL-LICENSE.txt) licenses.
|
||||
*
|
||||
* Built for jQuery library
|
||||
* http://jquery.com
|
||||
*
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
|
||||
$.fn.charCount = function(options){
|
||||
|
||||
// default configuration properties
|
||||
var defaults = {
|
||||
allowed: 140,
|
||||
warning: 25,
|
||||
css: 'counter',
|
||||
counterElement: 'span',
|
||||
cssWarning: 'warning',
|
||||
cssExceeded: 'exceeded',
|
||||
counterText: ''
|
||||
};
|
||||
|
||||
var options = $.extend(defaults, options);
|
||||
|
||||
function calculate(obj){
|
||||
var count = $(obj).val().length;
|
||||
var available = options.allowed - count;
|
||||
if(available <= options.warning && available >= 0){
|
||||
$(obj).next().addClass(options.cssWarning);
|
||||
} else {
|
||||
$(obj).next().removeClass(options.cssWarning);
|
||||
}
|
||||
if(available < 0){
|
||||
$(obj).next().addClass(options.cssExceeded);
|
||||
} else {
|
||||
$(obj).next().removeClass(options.cssExceeded);
|
||||
}
|
||||
$(obj).next().html(options.counterText + available);
|
||||
};
|
||||
|
||||
this.each(function() {
|
||||
$(this).after('<'+ options.counterElement +' class="' + options.css + '">'+ options.counterText +'</'+ options.counterElement +'>');
|
||||
calculate(this);
|
||||
$(this).keyup(function(){calculate(this)});
|
||||
$(this).change(function(){calculate(this)});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
61
public/javascripts/widgets/i18n.js
Normal file
61
public/javascripts/widgets/i18n.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* Created by .
|
||||
* User: dan
|
||||
* Date: Jan 25, 2011
|
||||
* Time: 5:18:32 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
Diaspora.widgets.add("i18n", function() {
|
||||
this.start = $.noop;
|
||||
|
||||
this.callbacks = [];
|
||||
this.language = undefined;
|
||||
this.locale = undefined;
|
||||
this.ready = false;
|
||||
|
||||
this.loadLocale = function(locale, language) {
|
||||
this.ready = true;
|
||||
this.language = language;
|
||||
|
||||
if(typeof locale !== "undefined") {
|
||||
this.locale = locale;
|
||||
this.triggerCallbacks();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this.locale) {
|
||||
function setLocale(data) {
|
||||
this.locale = $.parseJSON(data);
|
||||
this.triggerCallbacks();
|
||||
}
|
||||
|
||||
$.getJSON("/localize", setLocale);
|
||||
}
|
||||
};
|
||||
|
||||
this.triggerCallbacks = function() {
|
||||
for(var i = 0; i < this.callbacks.length; i++) {
|
||||
this.callbacks[i]();
|
||||
}
|
||||
};
|
||||
|
||||
this.onLocaleLoaded = function(callback) {
|
||||
if(this.ready) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
this.callbacks.push(callback);
|
||||
};
|
||||
|
||||
this.t = function(item, views) {
|
||||
var ret,
|
||||
_item = item.split(".");
|
||||
|
||||
while(part = _item.shift()) {
|
||||
ret = (ret) ? ret[part] : this.locale[part];
|
||||
}
|
||||
|
||||
return $.mustache(ret, views || {});
|
||||
};
|
||||
});
|
||||
41
public/javascripts/widgets/timeago.js
Normal file
41
public/javascripts/widgets/timeago.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Created by .
|
||||
* User: dan
|
||||
* Date: Jan 25, 2011
|
||||
* Time: 8:49:02 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
Diaspora.widgets.add("timeago", function() {
|
||||
this.start = function() {
|
||||
Diaspora.widgets.i18n.onLocaleLoaded(function() {
|
||||
|
||||
if(Diaspora.widgets.i18n.language === "en") {
|
||||
return;
|
||||
}
|
||||
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: Diaspora.widgets.i18n.t("timeago.prefixAgo"),
|
||||
prefixFromNow: Diaspora.widgets.i18n.t("timeago.prefixFromNow"),
|
||||
suffixAgo: Diaspora.widgets.i18n.t("timeago.suffixAgo"),
|
||||
suffixFromNow: Diaspora.widgets.i18n.t("timeago.suffixFromNow"),
|
||||
seconds: Diaspora.widgets.i18n.t("timeago.seconds"),
|
||||
minute: Diaspora.widgets.i18n.t("timeago.minute"),
|
||||
minutes: Diaspora.widgets.i18n.t("timeago.minutes"),
|
||||
hour: Diaspora.widgets.i18n.t("timeago.hour"),
|
||||
hours: Diaspora.widgets.i18n.t("timeago.hours"),
|
||||
day: Diaspora.widgets.i18n.t("timeago.day"),
|
||||
days: Diaspora.widgets.i18n.t("timeago.days"),
|
||||
month: Diaspora.widgets.i18n.t("timeago.month"),
|
||||
months: Diaspora.widgets.i18n.t("timeago.months"),
|
||||
year: Diaspora.widgets.i18n.t("timeago.year"),
|
||||
years: Diaspora.widgets.i18n.t("timeago.years")
|
||||
};
|
||||
|
||||
Diaspora.widgets.timeago.updateTimeAgo("abbr");
|
||||
});
|
||||
};
|
||||
|
||||
this.updateTimeAgo = function(selector) {
|
||||
$(selector).timeago();
|
||||
};
|
||||
});
|
||||
Loading…
Reference in a new issue