2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'gettext_i18n_rails_js/parser/javascript'
|
2018-11-20 20:47:30 +05:30
|
|
|
require 'json'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
module GettextI18nRailsJs
|
|
|
|
module Parser
|
|
|
|
module Javascript
|
|
|
|
# This is required to tell the `rake gettext:find` script to use the Javascript
|
|
|
|
# parser for *.vue files.
|
|
|
|
#
|
|
|
|
# Overwrites: https://github.com/webhippie/gettext_i18n_rails_js/blob/46c58db6d2053a4f5f36a0eb024ea706ff5707cb/lib/gettext_i18n_rails_js/parser/javascript.rb#L36
|
|
|
|
def target?(file)
|
|
|
|
[
|
|
|
|
".js",
|
|
|
|
".jsx",
|
|
|
|
".vue"
|
|
|
|
].include? ::File.extname(file)
|
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
def collect_for(file)
|
|
|
|
gettext_messages_by_file[file] || []
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def gettext_messages_by_file
|
2020-05-24 23:13:21 +05:30
|
|
|
@gettext_messages_by_file ||= Gitlab::Json.parse(load_messages)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def load_messages
|
|
|
|
`node scripts/frontend/extract_gettext_all.js --all`
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
class PoToJson
|
|
|
|
# This is required to modify the JS locale file output to our import needs
|
|
|
|
# Overwrites: https://github.com/webhippie/po_to_json/blob/master/lib/po_to_json.rb#L46
|
|
|
|
def generate_for_jed(language, overwrite = {})
|
|
|
|
@options = parse_options(overwrite.merge(language: language))
|
|
|
|
@parsed ||= inject_meta(parse_document)
|
|
|
|
|
|
|
|
generated = build_json_for(build_jed_for(@parsed))
|
|
|
|
[
|
|
|
|
"window.translations = #{generated};"
|
|
|
|
].join(" ")
|
|
|
|
end
|
|
|
|
end
|