toretore / babilu Goto Github PK
View Code? Open in Web Editor NEWABANDONED - Use i18n-js instead
License: MIT License
ABANDONED - Use i18n-js instead
License: MIT License
To make babilu compatible with rails 3 I18n interpolation syntax (e.g. ' you have %{amount} unread messages' (rather than the {{amount}} syntax)) I've changed the interpolatePattern in the top of babilu.js to:
var interpolatePattern = /%{([^}]+)}/g;
Maybe the interpolate regexp can be adjusted when generating locales.js based on the existence/value of RAILS_GEM_VERSION ?
In some configurations "rails server" refuses to start with: "/Users/nkuebler/projects/viewr/vendor/plugins/babilu/lib/babilu.rb:51:in `block in class:Railtie': You have a nil object when you didn't expect it! (NoMethodError)"
A possible fix is to change 'balibu.rb' from
class Railtie < Rails::Railtie
config.before_configuration do
config.action_view.javascript_expansions[:defaults] ||= [] << 'locales'
end
end if defined?(Rails::Railtie)
to
class Railtie < Rails::Railtie
config.before_configuration do
config.action_view.javascript_expansions ||= {}
config.action_view.javascript_expansions[:defaults] ||= [] << 'locales'
end
end if defined?(Rails::Railtie)
It would be nice if the gem was updated to generated the locales.js file in vendor/assets/javascripts/locales.js. Perhaps even better would be to make the path configurable but at least having it in a loaded directory would fix issues in 3.1
example:
in en.yml:
items_left:
one: '1 item left'
other: '{{count}} items left'
I18n.t('items_left', {'count': 0}) returns [Object Object] rather than the expected '0 items left'
This error is caused by the first line in the pluralize function:
I18n.pluralize = function(value, count){
if (!count) return value;
return count == 1 ? value.one : value.other;
};
The (!count) expression returns false when count is 0, causing the value object to be returned without choosing the correct plural form. The value object is an object containing the 'one' and 'other' keys, it doesn't really make sense to return it. In my opinion this if (!count) check can be safely removed, and the function changed to this:
I18n.pluralize = function(value, count){
return (typeof(count) !== 'undefined' && count == 1) ? value.one : value.other;
}
This way pluralize always returns a correct key.
After struggling with a JavaScript parse error in locales.js for quite a while, I determined the cause. The error is a missing } even though the code looks/lints fine. It is a result of multiple near-simultaneous requests in development mode.
We have a route to a stylesheet action that pulls the CSS from a database. When a page is hit (in development), the generate_locale_javascript filter is fired once for the page and again when the page loads the stylesheet action. My assumption is that this results in a partially overwritten locales.js being returned, hence the parse error.
My solution for now is as follows:
skip_after_filter :generate_locale_javascript, :only => :stylesheet
I'm submitting this so others are aware of the issue, and perhaps we can come up with a better solution in Babilu itself. Regenerating only if the yml files change should at least reduce, if not eliminate the issues.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.