Skip to content

Commit 4d4a71b

Browse files
committed
script to rewrite yaml files using psych
1 parent b314bf5 commit 4d4a71b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#-- copyright
5+
# OpenProject is an open source project management software.
6+
# Copyright (C) the OpenProject GmbH
7+
#
8+
# This program is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU General Public License version 3.
10+
#
11+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
12+
# Copyright (C) 2006-2013 Jean-Philippe Lang
13+
# Copyright (C) 2010-2013 the ChiliProject Team
14+
#
15+
# This program is free software; you can redistribute it and/or
16+
# modify it under the terms of the GNU General Public License
17+
# as published by the Free Software Foundation; either version 2
18+
# of the License, or (at your option) any later version.
19+
#
20+
# This program is distributed in the hope that it will be useful,
21+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
# GNU General Public License for more details.
24+
#
25+
# You should have received a copy of the GNU General Public License
26+
# along with this program; if not, write to the Free Software
27+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28+
#
29+
# See COPYRIGHT and LICENSE files for more details.
30+
#++
31+
32+
require "stringio"
33+
require "tempfile"
34+
require "yaml"
35+
36+
crowdin_yml_files = Dir.glob("{,modules/*/}config/locales/crowdin/*.yml")
37+
38+
rewritten_count = crowdin_yml_files.count do |path|
39+
content = File.read(path)
40+
comments = content.lines.take_while { it.start_with?("#") }
41+
data = YAML.safe_load(content, permitted_classes: [Symbol])
42+
43+
rewritten_content = StringIO.open do |io|
44+
io.puts comments
45+
YAML.dump(data, io)
46+
47+
io.string
48+
end
49+
50+
next if rewritten_content == content
51+
52+
Tempfile.create(File.basename(path), File.dirname(path)) do |tmp|
53+
tmp.write(rewritten_content)
54+
tmp.close
55+
File.rename(tmp.path, path)
56+
end
57+
end
58+
59+
puts "Rewrote #{rewritten_count} crowdin YAML files"

0 commit comments

Comments
 (0)