]> pere.pagekite.me Git - text-madewithcc.git/blob - fixup.rb
Translated using Weblate (Spanish)
[text-madewithcc.git] / fixup.rb
1 #!/usr/bin/ruby
2 # coding: utf-8
3 raise ArgumentError, 'Source/destination files not specified' if ARGV.size != 2
4 srcfile = ARGV[0]
5 dstfile = ARGV[1]
6
7 data=File.open(srcfile).readlines.map {|l| l.chomp!}
8
9 data.map {|lin| lin.gsub!(/<span id="anchor-?\d*"><\/span>/, '')}
10
11 # There are several titles that are spread in more than one line. Make
12 # them into translatable sentences.
13 [ ['Made', '', 'with', '', 'Creative', '', 'Commons'],
14 ['The New','', 'World of', '', 'Digital', '', 'Commons'],
15 ['How', '', 'to Be', '', 'Made with', '', 'Creative', '', 'Commons'],
16 ['Use CC to get attribution and name', 'recognition'],
17 ['Use CC to enable hands-on engagement with', 'your work'],
18 ['Providing a custom service to consumers of', 'your work * \[MARKET-BASED\]*'],
19 ['Charging for the physical copy *', '\[MARKET-BASED\]*'],
20 ['Charging for the in-person version *','\[MARKET-BASED\]*'],
21 ['Charging advertisers or sponsors *', '\[MARKET-BASED\]*'],
22 ['Charging your content creators *', '\[MARKET-BASED\]*'],
23 ['Charging a transaction fee *', '\[MARKET-BASED\]*'],
24 ['Providing a service to your creators*', '\[MARKET-BASED\]*'],
25 ['Memberships and individual donations', '*\[RECIPROCITY-BASED\]*'],
26 ['The pay-what-you-want model', '*\[RECIPROCITY-BASED\]*'],
27 ['The', '', 'Creative', '', 'Commons', '', 'Licenses'],
28 ['PLOS','', '(Public Library of Science)']
29 ].each do |str|
30 # This should be done more generic, more robust... But before
31 # burning brain cells, verify if it's needed!
32 if (data.select {|i| i == str[0]}.size != 1)
33 raise RuntimeError, 'First string appears multiple times: %s (%s)' %
34 [str.reject{|i| i==''}.join(' '), str[0]]
35 end
36
37 len = str.size
38 at = data.index(str[0])
39 joined = str.reject {|word| word==''}.join(' ')
40 len.times do |offset|
41 if str[offset] != data[at+offset]
42 raise RuntimeError,
43 'Warning: String does not match ("%s" of "%s", offset %d, book at %d)' %
44 [str[offset], joined, offset, at+offset]
45 end
46 end
47
48 data[at] = joined
49 (str.size - 1).times { data.delete_at(at+1) }
50 end
51
52 # Mark up headings: Very artisanal and suboptimal, but should do the
53 # trick.
54 #
55 # For every heading, put here the full string and its heading level,
56 # as follows:
57 #
58 # 1 - Part
59 # 2 - Chapter
60 # 3 - Section
61 # 4 - Subsection
62 #
63 # Try to keep this ordered as it appears within the book, as it will
64 # help us spot omissions and mistakes!
65 [ [2, 'Foreword'],
66 [2, 'Introduction'],
67 [1, 'Part 1'],
68 [1, 'The Big Picture'],
69 [2, 'The New World of Digital Commons'],
70 [3, 'The Commons, the Market, and the State'],
71 [3, 'The Four Aspects of a Resource'],
72 [4, 'Characteristics'],
73 [4, 'People and processes'],
74 [4, 'Norms and rules'],
75 [4, 'Goals'],
76 [3, 'A Short History of the Commons'],
77 [3, 'The Digital Revolution'],
78 [3, 'The Birth of Creative Commons'],
79 [3, 'The Changing Market'],
80 [3, 'Benefits of the Digital Commons'],
81 [3, 'Our Case Studies'],
82 [3, 'Notes'],
83 [2, 'How to Be Made with Creative Commons'],
84 [3, 'Problem Zero: Getting Discovered'],
85 [4, 'Use CC to grow a larger audience'],
86 [4, 'Use CC to get attribution and name recognition'],
87 [4, 'Use CC-licensed content as a marketing tool'],
88 [4, 'Use CC to enable hands-on engagement with your work'],
89 [4, 'Use CC to differentiate yourself'],
90 [3, 'Making Money'],
91 [4, 'Market-based revenue streams'],
92 [4, 'Providing a custom service to consumers of your work * \[MARKET-BASED\]*'],
93 [4, 'Charging for the physical copy * \[MARKET-BASED\]*'],
94 [4, 'Charging for the in-person version * \[MARKET-BASED\]*'],
95 [4, 'Selling merchandise * \[MARKET-BASED\]*'],
96 [4, 'Charging advertisers or sponsors * \[MARKET-BASED\]*'],
97 [4, 'Charging your content creators * \[MARKET-BASED\]*'],
98 [4, 'Charging a transaction fee * \[MARKET-BASED\]*'],
99 [4, 'Providing a service to your creators* \[MARKET-BASED\]*'],
100 [4, 'Licensing a trademark* \[MARKET-BASED\]*'],
101 [4, 'Reciprocity-based revenue streams'],
102 [4, 'Memberships and individual donations *\[RECIPROCITY-BASED\]*'],
103 [4, 'The pay-what-you-want model *\[RECIPROCITY-BASED\]*'],
104 [4, 'Crowdfunding *\[RECIPROCITY-BASED\]*'],
105 [3, 'Making Human Connections'],
106 [4, 'Be human'],
107 [4, 'Be open and accountable'],
108 [4, 'Design for the good actors'],
109 [4, 'Treat humans like, well, humans'],
110 [4, 'State your principles and stick to them'],
111 [4, 'Build a community'],
112 [4, 'Give more to the commons than you take'],
113 [4, 'Involve people in what you do'],
114 [4, 'Notes'],
115 [2, 'The Creative Commons Licenses'],
116 [1, 'Part 2'],
117 [1, 'The Case Studies'],
118 [2, 'Arduino'],
119 [2, 'Ártica'],
120 [2, 'Blender Institute'],
121 [2, 'Cards Against Humanity'],
122 [2, 'The Conversation'],
123 [2, 'Cory Doctorow'],
124 [2, 'Figshare'],
125 [2, 'Figure.NZ'],
126 [2, 'Knowledge Unlatched'],
127 [2, 'Lumen Learning'],
128 [2, 'Jonathan Mann'],
129 [2, 'Noun Project'],
130 [2, 'Open Data Institute'],
131 [2, 'OpenDesk'],
132 [2, 'OpenStax'],
133 [2, 'Amanda Palmer'],
134 [2, 'PLOS (Public Library of Science)'],
135 [2, 'Rijksmuseum'],
136 [2, 'Shareable'],
137 [2, 'Siyavula'],
138 [2, 'Sparkfun'],
139 [2, 'TeachAIDS'],
140 [2, 'Tribe of Noise'],
141 [2, 'Wikimedia Foundation'],
142 [2, 'Bibliography'],
143 [2, 'Acknowledgments'],
144
145 ].each do |item|
146 at = data.index {|i| i == item[1]}
147 if at.nil?
148 raise RuntimeError, 'Heading string (level %d) not found: «%s»' % item
149 end
150 data[at] = '%s %s' % ['#' * item[0], data[at]]
151 end
152
153
154
155 # Join erroneously split paragraphs
156 ['to the values symbolized by',
157 'the kinds of participative communities that drive open',
158 'At a minimum, a CC-',
159 'easier to trust a',
160 'free download, the',
161 'openness to fans remixing the game—give',
162 'Attribution-',
163 'both journal publishers and researchers. Figshare now provides',
164 'get the “network effect”—',
165 'access to scholarly books. For Frances, the current scholarly-',
166 'for-',
167 'sales',
168 'contributing to the open',
169 'doesn’t seem like it should be sung about',
170 'songwriter, and he has found a way to keep it interesting for',
171 'building trust is the top',
172 'license',
173 'authors and Shuttleworth; Mark remains incredibly proud of this',
174 'BY-SA and opting in others with collecting societies like',
175 'Cecilie Maria, Cedric Howe, Cefn Hoile,',
176 'Braddlee, Drew Spencer, Duncan',
177 'Elizabeth Holloway, Ellen Buecher, Ellen Kaye-',
178 'Helen',
179 ].each do |line|
180 at = data.index {|i| i == line}
181 if !at.nil? and data[at+1] == ''
182 data.delete_at(at+1)
183 end
184 end
185
186 File.open(dstfile, 'w') {|f| f.puts data.join("\n")}