Module: Localeapp::HandlebarsI18n
- Defined in:
- lib/localeapp-handlebars_i18n.rb,
lib/localeapp-handlebars_i18n/version.rb
Overview
A singleton module that reports missing translations found in handebars templates to Localeapp. Once you have set everything up with configure it is a simple matter of calling Localeapp::HandlebarsI18n.send_missing_translations and you are done.
Constant Summary collapse
- VERSION =
The current version
'0.0.1'
Class Method Summary collapse
-
.configure(output = $stdout, &block) ⇒ Object
configures HanldebarsI18n.
- .default_locale ⇒ Object
-
.default_locale=(locale) ⇒ Object
The default locale to load when comparing handlebar translation keys and I18n translation keys.
- .hbs_helper ⇒ Object
-
.hbs_helper=(helper) ⇒ Object
The string name of your handlebars helper function for translation.
-
.hbs_load_path ⇒ Array
Returns the files you specified or an empty array.
-
.hbs_load_path=(files) ⇒ Object
Sets the array of handlebars templates that will be searched for localization helpers.
-
.localeapp_api_key=(api_key) ⇒ Object
Configures localeapp to use the api key you specify when reporting missing translations.
-
.send_missing_translations ⇒ Object
Sends any missing translations to Localeapp.
-
.yml_load_path ⇒ String
This defines the yml file to load for I18n.
-
.yml_load_path=(dir) ⇒ Object
The directory where your locale .yml files live.
Class Method Details
.configure(output = $stdout, &block) ⇒ Object
configures HanldebarsI18n
23 24 25 26 27 |
# File 'lib/localeapp-handlebars_i18n.rb', line 23 def configure(output = $stdout, &block) @output = output instance_eval &block if block_given? register_missing_translations end |
.default_locale ⇒ Object
59 60 61 |
# File 'lib/localeapp-handlebars_i18n.rb', line 59 def default_locale @default_locale ||= :en end |
.default_locale=(locale) ⇒ Object
The default locale to load when comparing handlebar translation keys and I18n translation keys. This is used when loading YAML data into I18n’s simple backend
54 55 56 |
# File 'lib/localeapp-handlebars_i18n.rb', line 54 def default_locale=(locale) @default_locale = locale end |
.hbs_helper ⇒ Object
47 48 49 |
# File 'lib/localeapp-handlebars_i18n.rb', line 47 def hbs_helper @hbs_helper ||= 't' end |
.hbs_helper=(helper) ⇒ Object
The string name of your handlebars helper function for translation. Here is an example coffeescript handlebars helper registration that creates a helper named ‘t’ that uses I18n-js for javascript localizations. If you had a helper like the one below, you would pass ‘t’ into this method. ‘t’ is also the default so if you are already using a helper named ‘t’ you do not need to configure this.
This helper is interpolated into the regular expression used to scan for translation keys: “{{#{hbs_helper} (.*?)}}”
42 43 44 |
# File 'lib/localeapp-handlebars_i18n.rb', line 42 def hbs_helper=(helper) @hbs_helper end |
.hbs_load_path ⇒ Array
Returns the files you specified or an empty array
85 86 87 |
# File 'lib/localeapp-handlebars_i18n.rb', line 85 def hbs_load_path @hbs_load_path ||= [] end |
.hbs_load_path=(files) ⇒ Object
Sets the array of handlebars templates that will be searched for localization helpers. Dir.glob is pretty dang handy here.
79 80 81 |
# File 'lib/localeapp-handlebars_i18n.rb', line 79 def hbs_load_path=(files) @hbs_load_path = files.flatten end |
.localeapp_api_key=(api_key) ⇒ Object
Configures localeapp to use the api key you specify when reporting missing translations.
91 92 93 94 95 |
# File 'lib/localeapp-handlebars_i18n.rb', line 91 def localeapp_api_key=(api_key) Localeapp.configure do |config| config.api_key= api_key end end |
.send_missing_translations ⇒ Object
If you have not configured Localeapp::HandlebarsI18n you will recieve an error with an example on how to do so.
Sends any missing translations to Localeapp.
99 100 101 102 103 104 |
# File 'lib/localeapp-handlebars_i18n.rb', line 99 def send_missing_translations ensure_configured return if Localeapp.missing_translations[default_locale].empty? @output.puts "sending missing translations to localeapp" Localeapp::sender.post_missing_translations end |
.yml_load_path ⇒ String
This defines the yml file to load for I18n. It retuns an interpolated string of the yml_load_path value you configured and the default locale.
72 73 74 |
# File 'lib/localeapp-handlebars_i18n.rb', line 72 def yml_load_path "#{@yml_load_path}/#{default_locale}.yml" end |
.yml_load_path=(dir) ⇒ Object
The directory where your locale .yml files live.
65 66 67 |
# File 'lib/localeapp-handlebars_i18n.rb', line 65 def yml_load_path=(dir) @yml_load_path = dir end |