2020-06-02 17:33:10 +00:00
|
|
|
def create_iso639_language_list_file
|
2020-06-28 12:02:45 +00:00
|
|
|
cpp_file_name = "src/common/iso639_language_list.cpp"
|
2021-02-17 16:39:42 +00:00
|
|
|
iso639_2 = JSON.parse(IO.readlines("/usr/share/iso-codes/json/iso_639-2.json").join('')) \
|
|
|
|
["639-2"].
|
2020-06-02 17:33:10 +00:00
|
|
|
reject { |entry| %r{^qaa}.match(entry["alpha_3"]) }.
|
2021-02-17 16:39:42 +00:00
|
|
|
map do |entry|
|
|
|
|
entry["has_639_2"] = true
|
|
|
|
entry["alpha_3_to_use"] = entry["bibliographic"] || entry["alpha_3"]
|
|
|
|
entry
|
|
|
|
end
|
|
|
|
|
|
|
|
used_codes = Hash[ *iso639_2.map { |entry| [ entry["alpha_3"], true, entry["bibliographic"], true ] }.flatten ]
|
|
|
|
|
|
|
|
JSON.parse(IO.readlines("/usr/share/iso-codes/json/iso_639-3.json").join('')) \
|
|
|
|
["639-3"].
|
|
|
|
reject { |entry| entry["type"] != "L" }.
|
|
|
|
reject { |entry| used_codes.include?(entry["alpha_3"]) }.
|
|
|
|
each do |entry|
|
|
|
|
iso639_2 << {
|
|
|
|
"name" => entry["name"],
|
|
|
|
"alpha_3" => entry["alpha_3"],
|
|
|
|
"alpha_3_to_use" => entry["alpha_3"],
|
|
|
|
"has_639_2" => false,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
rows = iso639_2.
|
2020-06-02 17:33:10 +00:00
|
|
|
map do |entry|
|
2020-06-28 12:02:45 +00:00
|
|
|
[ entry["name"].to_u8_cpp_string,
|
2021-02-17 16:39:42 +00:00
|
|
|
entry["alpha_3_to_use"].to_cpp_string,
|
2020-06-28 12:02:45 +00:00
|
|
|
(entry["alpha_2"] || '').to_cpp_string,
|
|
|
|
entry["bibliographic"] ? entry["alpha_3"].to_cpp_string : '""s',
|
2021-02-17 16:39:42 +00:00
|
|
|
entry["has_639_2"].to_s,
|
2020-06-02 17:33:10 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
rows += ("a".."d").map do |letter|
|
2021-01-25 23:06:46 +00:00
|
|
|
[ %Q{u8"Reserved for local use: qa#{letter}"s},
|
|
|
|
%Q{u8"qa#{letter}"s},
|
2020-06-28 12:02:45 +00:00
|
|
|
'""s',
|
|
|
|
'""s',
|
2021-01-24 21:05:34 +00:00
|
|
|
'true ',
|
2020-06-02 17:33:10 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
header = <<EOT
|
|
|
|
/*
|
|
|
|
mkvmerge -- utility for splicing together matroska files
|
|
|
|
from component media subtypes
|
|
|
|
|
|
|
|
Distributed under the GPL v2
|
|
|
|
see the file COPYING for details
|
2020-08-01 16:03:54 +00:00
|
|
|
or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2020-06-02 17:33:10 +00:00
|
|
|
|
|
|
|
ISO 639 language definitions, lookup functions
|
|
|
|
|
|
|
|
Written by Moritz Bunkus <moritz@bunkus.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// NOTE: this file is auto-generated by the "dev:iso639_list" rake target.
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2021-02-17 16:21:10 +00:00
|
|
|
#include "common/iso639_types.h"
|
2020-06-02 17:33:10 +00:00
|
|
|
|
2021-02-17 16:21:10 +00:00
|
|
|
using namespace std::string_literals;
|
2020-06-02 17:33:10 +00:00
|
|
|
|
2020-07-04 11:36:50 +00:00
|
|
|
namespace mtx::iso639 {
|
|
|
|
|
2021-01-25 23:06:46 +00:00
|
|
|
std::vector<language_t> g_languages;
|
|
|
|
|
|
|
|
void
|
|
|
|
init() {
|
|
|
|
g_languages.reserve(#{rows.size});
|
|
|
|
|
2020-06-02 17:33:10 +00:00
|
|
|
EOT
|
|
|
|
|
|
|
|
footer = <<EOT
|
2021-01-25 23:06:46 +00:00
|
|
|
}
|
2020-07-04 11:36:50 +00:00
|
|
|
|
|
|
|
} // namespace mtx::iso639
|
2020-06-02 17:33:10 +00:00
|
|
|
EOT
|
|
|
|
|
2021-01-25 23:06:46 +00:00
|
|
|
content = header + format_table(rows.sort, :column_suffix => ',', :row_prefix => " g_languages.emplace_back(", :row_suffix => ");").join("\n") + "\n" + footer
|
2020-06-02 17:33:10 +00:00
|
|
|
|
2020-06-28 12:02:45 +00:00
|
|
|
runq("write", cpp_file_name) { IO.write("#{$source_dir}/#{cpp_file_name}", content); 0 }
|
2020-06-02 17:33:10 +00:00
|
|
|
end
|