Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New statistics endpoint for integrations

  • Loading branch information...
commit 997231b9766ea459543ed2932e9172863cdf3516 1 parent b555bf0
@fcsonline fcsonline authored
View
19 app/controllers/tolk/locales_controller.rb
@@ -6,7 +6,7 @@ class LocalesController < Tolk::ApplicationController
def index
@locales = Tolk::Locale.secondary_locales.sort_by(&:language_name)
end
-
+
def show
respond_to do |format|
format.html do
@@ -43,6 +43,23 @@ def dump_all
redirect_to request.referrer
end
+ def stats
+ @locales = Tolk::Locale.secondary_locales.sort_by(&:language_name)
+
+ respond_to do |format|
+ format.json do
+ stats = @locales.collect do |locale|
+ [locale.name, {
+ :missing => locale.count_phrases_without_translation,
+ :updated => locale.count_phrases_with_updated_translation,
+ :updated_at => locale.updated_at
+ }]
+ end
+ render :json => Hash[stats]
+ end
+ end
+ end
+
private
def find_locale
View
4 app/models/tolk/locale.rb
@@ -89,6 +89,10 @@ def count_phrases_without_translation
Tolk::Phrase.count - existing_ids.count
end
+ def count_phrases_with_updated_translation(page = nil)
+ find_phrases_with_translations(page, :'tolk_translations.primary_updated' => true).count
+ end
+
def phrases_without_translation(page = nil, options = {})
phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
View
2  config/routes.rb
@@ -2,6 +2,8 @@
root :to => 'locales#index'
post "/dump_all" => "locales#dump_all", :as => :dump_all_locales
+ get "/stats" => "locales#stats"
+
resources :locales do
member do
get :all
Please sign in to comment.
Something went wrong with that request. Please try again.