aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/attachment_to_html/adapters/pdf.rb3
-rw-r--r--lib/category_and_heading_migrator.rb91
-rw-r--r--lib/configuration.rb1
-rw-r--r--lib/languages.rb2
-rw-r--r--lib/public_body_categories.rb11
-rw-r--r--lib/tasks/gettext.rake47
6 files changed, 49 insertions, 106 deletions
diff --git a/lib/attachment_to_html/adapters/pdf.rb b/lib/attachment_to_html/adapters/pdf.rb
index b91958c52..3183d1fd0 100644
--- a/lib/attachment_to_html/adapters/pdf.rb
+++ b/lib/attachment_to_html/adapters/pdf.rb
@@ -73,11 +73,10 @@ module AttachmentToHTML
html = AlaveteliExternalCommand.run("pdftohtml",
"-nodrm", "-zoom", "1.0", "-stdout", "-enc", "UTF-8",
- "-noframes", tempfile.path, :timeout => 30
+ "-noframes", tempfile.path, :timeout => 30, :binary_output => false
)
cleanup_tempfile(tempfile)
-
html
end
end
diff --git a/lib/category_and_heading_migrator.rb b/lib/category_and_heading_migrator.rb
deleted file mode 100644
index 402ea7204..000000000
--- a/lib/category_and_heading_migrator.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-module CategoryAndHeadingMigrator
-
- # This module migrates data from public_body_categories_[locale].rb files
- # into PublicBodyHeading and PublicBodyCategory models
-
- # Load all the data from public_body_categories_[locale].rb files.
- def self.migrate_categories_and_headings
- if PublicBodyCategory.count > 0
- puts "PublicBodyCategories exist already, not migrating."
- else
- @first_locale = true
- I18n.available_locales.each do |locale|
- begin
- load "public_body_categories_#{locale}.rb"
- rescue MissingSourceFile
- end
- @first_locale = false
- end
- end
- end
-
- # Load the categories and headings for a locale
- def self.add_categories_and_headings_from_list(locale, data_list)
- # set the counter for headings loaded from this locale
- @@locale_heading_display_order = 0
- current_heading = nil
- data_list.each do |list_item|
- if list_item.is_a?(Array)
- # item is list of category data
- add_category(list_item, current_heading, locale)
- else
- # item is heading name
- current_heading = add_heading(list_item, locale, @first_locale)
- end
- end
- end
-
- def self.add_category(category_data, heading, locale)
- tag, title, description = category_data
- category = PublicBodyCategory.find_by_category_tag(tag)
- if category
- add_category_in_locale(category, title, description, locale)
- else
- category = PublicBodyCategory.create(:category_tag => tag,
- :title => title,
- :description => description)
-
- # add the translation if this is not the default locale
- # (occurs when a category is not defined in default locale)
- unless category.translations.map { |t| t.locale }.include?(locale)
- add_category_in_locale(category, title, description, locale)
- end
- end
- heading.add_category(category)
- end
-
- def self.add_category_in_locale(category, title, description, locale)
- I18n.with_locale(locale) do
- category.title = title
- category.description = description
- category.save
- end
- end
-
- def self.add_heading(name, locale, first_locale)
- heading = nil
- I18n.with_locale(locale) do
- heading = PublicBodyHeading.find_by_name(name)
- end
- # For multi-locale installs, we assume that all public_body_[locale].rb files
- # use the same headings in the same order, so we add translations to the heading
- # that was in the same position in the list loaded from other public_body_[locale].rb
- # files.
- if heading.nil? && !@first_locale
- heading = PublicBodyHeading.where(:display_order => @@locale_heading_display_order).first
- end
-
- if heading
- I18n.with_locale(locale) do
- heading.name = name
- heading.save
- end
- else
- I18n.with_locale(locale) do
- heading = PublicBodyHeading.create(:name => name)
- end
- end
- @@locale_heading_display_order += 1
- heading
- end
-end
diff --git a/lib/configuration.rb b/lib/configuration.rb
index 2144f9954..90fd30d5f 100644
--- a/lib/configuration.rb
+++ b/lib/configuration.rb
@@ -19,6 +19,7 @@ module AlaveteliConfiguration
:ADMIN_PASSWORD => '',
:ADMIN_USERNAME => '',
:ALLOW_BATCH_REQUESTS => false,
+ :AUTHORITY_MUST_RESPOND => true,
:AVAILABLE_LOCALES => '',
:BLACKHOLE_PREFIX => 'do-not-reply-to-this-address',
:BLOG_FEED => '',
diff --git a/lib/languages.rb b/lib/languages.rb
index 85d2d5950..a45071a67 100644
--- a/lib/languages.rb
+++ b/lib/languages.rb
@@ -36,7 +36,7 @@ class LanguageNames
'kw' => 'Kernewek',
'co' => 'corsu',
'cr' => 'ᓀᐦᐃᔭᐍᐏᐣ',
- 'hr' => 'hrvatski',
+ 'hr' => 'Hrvatski',
'cs' => 'česky',
'da' => 'dansk',
'dv' => 'ދިވެހި',
diff --git a/lib/public_body_categories.rb b/lib/public_body_categories.rb
deleted file mode 100644
index 3528e85b1..000000000
--- a/lib/public_body_categories.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# Allow the PublicBodyCategory model to be addressed using the same syntax
-# as the old PublicBodyCategories class without needing to rename everything,
-# make sure we're not going to break any themes
-class PublicBodyCategories
-
- def self.method_missing(method, *args, &block)
- warn 'Use of PublicBodyCategories is deprecated and will be removed in release 0.21. Please use PublicBodyCategory instead.'
- PublicBodyCategory.send(method, *args, &block)
- end
-
-end
diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake
index 9bdb6169b..4df92b008 100644
--- a/lib/tasks/gettext.rake
+++ b/lib/tasks/gettext.rake
@@ -35,14 +35,59 @@ namespace :gettext do
end
end
+ desc 'Update locale files with slightly changed English msgids using a csv file of old to new strings'
+ task :update_msgids_from_csv do
+ mapping_file = find_mapping_file(ENV['MAPPING_FILE'])
+ mappings = {}
+ CSV.parse(clean_csv_mapping_file(mapping_file)) do |csv_line|
+ from,to = csv_line
+ mappings[from] = to
+ end
+ Dir.glob("locale/**/app.po").each do |po_file|
+ lang_mappings = mappings.clone
+ lines = []
+ File.read(po_file).each_line do |line|
+ /^msgid "(.*)"/ =~ line
+ if $1 && mappings[$1]
+ lines << "msgid \"#{lang_mappings.delete($1)}\""
+ else
+ lines << line
+ end
+ end
+ puts "Mappings unused in #{po_file}: #{lang_mappings.keys}" unless lang_mappings.empty?
+ File.open(po_file, "w") { |f| f.puts(lines) }
+ end
+ end
+
+ # Use a quote for quote-escaping as CSV errors on the \" with "Missing or stray quote"
+ def clean_csv_mapping_file(file)
+ data = ''
+ File.foreach(file) do |line|
+ data += line.gsub('\"', '""')
+ end
+ data
+ end
+
def find_theme(theme)
unless theme
puts "Usage: Specify an Alaveteli-theme with THEME=[theme directory name]"
- exit(0)
+ exit(1)
end
theme
end
+ def find_mapping_file(file)
+ unless file
+ puts "Usage: Specify a csv file mapping old to new strings with MAPPING_FILE=[file name]"
+ exit(1)
+ end
+ unless File.exists?(file)
+ puts "Error: MAPPING_FILE #{file} not found"
+ exit(1)
+ end
+ file
+ end
+
def theme_files_to_translate(theme)
Dir.glob("{lib/themes/#{theme}/lib}/**/*.{rb,erb}")
end