Closed ellcs closed 4 years ago
diff --git a/lib/gettext/tools/parser/glade.rb b/lib/gettext/tools/parser/glade.rb
index 31fce5a..daf4f04 100644
--- a/lib/gettext/tools/parser/glade.rb
+++ b/lib/gettext/tools/parser/glade.rb
@@ -21,20 +21,29 @@ module GetText
class << self
XML_RE = /<\?xml/
- GLADE_RE = /glade-2.0.dtd/
+ GLADE_RELEASE_OLD = /glade-2.0.dtd/
+ GLADE_RELEASE = /<!-- Generated with glade/
def target?(file) # :nodoc:
data = IO.readlines(file)
- if XML_RE =~ data[0] and GLADE_RE =~ data[1]
+ if starts_with_xml_tag?(data) && includes_glade_tag?(data)
true
+ elsif File.extname(file) == '.glade'
+ raise _("`%{file}' is not glade-2.0 format.") % {:file => file}
else
- if File.extname(file) == '.glade'
- raise _("`%{file}' is not glade-2.0 format.") % {:file => file}
- end
false
end
end
+ def starts_with_xml_tag?(data)
+ data[0] =~ XML_RE
+ end
+
+ def includes_glade_tag?(data)
+ second_line = data[1]
+ GLADE_RELEASE_OLD =~ second_line || GLADE_RELEASE =~ second_line
+ end
+
def parse(path, options={})
parser = new(path, options)
parser.parse
Recent Glade uses GtkBuilder's UI definitions format that uses .ui
as extension.
We need to add support for .ui
.
@kou i'd like to resolve this issue. Do you think those two steps are enough for a PR?
GladeParser::target?
However, i wonder how to provide useful tests or test files. The old glade test files seem quite out of date.
We should not remove the current Glade parser.
We should add a new parser for the GtkBuilder: lib/gettext/tools/parser/gtk_builder.rb
We need to add a new .ui
files for test. We can create those files by recent Glade.
I've implemented.
Thank you! I will have a look. :+1:
Hello there! Before i start complaining, i would like to thank you for your work! :) I do use the
glade
version3.22.1
and the most recent version of the gettext ruby gem. Within the project, i do useGetText::Tools::Task
to define a rake task. In order to fetch various translation changes within the glade file.All widgets, locales and po files are valid. When i run
rake gettext:po:update
to fetch changes within the glade file, i receive an error:widget is not glade-2.0 format.
.The problem is located in file
lib/gettext/tools/parser/glade.rb
.gettext
validates the gladefile, with two checks. The second check causes trouble. It assumes that the first two lines look like this (I copied it from gettext/samples/hello_glade2.glade):I tried to open the sample file, with glade. But glade threw an error. My glade file started with those lines:
Workaround
I simply added a second Regex to check if the second line starts with
<!-- Generated with glade
. And guess what, my po files are correctly updated and i do not receive errors anymore. I will attach the patch.