File tree Expand file tree Collapse file tree 3 files changed +10
-13
lines changed
Expand file tree Collapse file tree 3 files changed +10
-13
lines changed Original file line number Diff line number Diff line change @@ -112,25 +112,22 @@ FTL.Message = class(FluentNode)
112112FTL .Message ._name = " Message"
113113
114114function FTL .Message :_init (ast , resource )
115- self .attributes = setmetatable ({}, {
116- map = {}
117- })
115+ self .attributes = setmetatable ({}, { map = {} })
118116 self :super (ast , resource )
119- -- Penlight bug #307, should be — self:catch(self.get_attribute)
120- self :catch (function (_ , attribute ) return self :get_attribute (attribute ) end )
117+ self :catch (self .get_attribute )
121118end
122119
123120function FTL .Message :set_attribute (attribute )
121+ local attributes = rawget (self , " attributes" )
124122 local id = attribute .id .name
125- local attributes = self .attributes
126123 local map = getmetatable (attributes ).map
127124 local k = # attributes + 1
128125 attributes [k ] = attribute
129126 map [id ] = k
130127end
131128
132129function FTL .Message :get_attribute (attribute )
133- local attributes = self . attributes
130+ local attributes = rawget ( self , " attributes" ) or error ( " No attributes " )
134131 local map = getmetatable (attributes ).map
135132 local k = map [attribute ]
136133 return attributes [k ]
Original file line number Diff line number Diff line change @@ -9,11 +9,11 @@ local FluentResource = require("fluent.resource")
99
1010local FluentBundle = class ()
1111FluentBundle .locales = {}
12+ FluentBundle .locale = " und"
1213
1314function FluentBundle :_init (locale )
1415 self :set_locale (locale )
15- -- Penlight bug #307, should be — self:catch(self.get_message)
16- self :catch (function (_ , identifier ) return self :get_message (identifier ) end )
16+ self :catch (self .get_message )
1717end
1818
1919function FluentBundle :set_locale (locale )
@@ -24,9 +24,10 @@ function FluentBundle:set_locale (locale)
2424end
2525
2626function FluentBundle :get_message (identifier )
27- local locales = rawget (self , " locales" )
27+ local locales = self .locales
28+ local locale = self .locale
29+ local resource = locales [locale ]
2830 -- TODO iterate over fallback locales if not found in current one
29- local resource = rawget (locales , self .locale )
3031 return resource :get_message (identifier ) or nil
3132end
3233
Original file line number Diff line number Diff line change @@ -42,8 +42,7 @@ function FluentResource:_init (ast)
4242 end
4343 end
4444 flush ()
45- -- Penlight bug #307, should be — self:catch(self.get_message)
46- self :catch (function (_ , identifier ) return self :get_message (identifier ) end )
45+ self :catch (self .get_message )
4746end
4847
4948function FluentResource :load_node (node )
You can’t perform that action at this time.
0 commit comments