There are some utilities when you find that your already translated keys need manipulating (splitting, combining, find and replace)
project = Project.find_by_name("Some project")
project.master_texts.with_keys("some_prefix_c_01_header").each do |master_text|
master_text.update!(key: "some_prefix_c_01_heading")
end
split some_prefix_c_01_md into separate paragraphs (to some_prefix_c_01_P0x)
project.master_texts.with_keys("some_prefix_c_01_md").each do |master_text|
master_text.md_to_paragraphs!(base_key: "some_prefix_c_01")
end
for each of some_prefix_c_0x_md split into some_prefix_c_0x_heading and some_prefix_c_0x_body_md
project.master_texts.with_keys(/some_prefix_c_\d+_md/).each do |master_text|
master_text.md_to_heading_and_text!
end
split out some_prefix_c_02_body -- into some_prefix_c_02_0N_heading and some_prefix_c_02_0N_para (alternate paragraphs)
project.master_texts.with_keys("some_prefix_c_02_text").each do |master_text|
master_text.split_to_sections(base_key: "some_prefix_c_02")
end
project.find_and_replace(
"DBA Megacorp" => "Megacorp Inc",
"Captain Fun" => "Mr Serious",
)
e.g. fix up french punctuation:
french = Language.find_by_name("French")
nbsp = [160].pack('U*')
french.project_languages.flat_map(&:localized_texts).each do |lt|
transformed = lt.other.gsub(/[ #{nbsp}]?([:;!?»])[ #{nbsp}]?/, "#{nbsp}\\1 ")
transformed = transformed.gsub(/[ #{nbsp}]?([«])[ #{nbsp}]?/, " \\1#{nbsp}").strip
transformed = transformed.gsub(%r<#{nbsp}:#{nbsp}//>, "://")
transformed.chop! if transformed.ends_with?(nbsp)
lt.update(other: transformed) unless transformed == lt.other
end; nil
french.project_languages.each(&:recalculate_counts!); nil