Remove old script files
This commit is contained in:
parent
b0434c8b79
commit
34405b8e61
|
@ -1,45 +0,0 @@
|
||||||
# Install transifex-ruby - https://rubygems.org/gems/transifex-ruby
|
|
||||||
#
|
|
||||||
# Create a file called pull_locales_login.rb.
|
|
||||||
# Contents should be:
|
|
||||||
#
|
|
||||||
# Transifex.configure do |config|
|
|
||||||
# config.username = 'transifex.username'
|
|
||||||
# config.password = 'transifex.password'
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# Update require_relative to point to this file.
|
|
||||||
|
|
||||||
require 'transifex'
|
|
||||||
require 'fileutils'
|
|
||||||
require_relative '../stylish-chrome-bin/pull_locales_login'
|
|
||||||
|
|
||||||
project_slug = 'stylish-for-chrome'
|
|
||||||
|
|
||||||
transifex = Transifex::Client.new
|
|
||||||
project = transifex.project(project_slug)
|
|
||||||
|
|
||||||
project.languages.each do |language|
|
|
||||||
code = language.language_code
|
|
||||||
puts "Getting locale #{code}"
|
|
||||||
dir_name = "../_locales/#{code}"
|
|
||||||
Dir.mkdir(dir_name) if !Dir.exist?(dir_name)
|
|
||||||
has_content = false
|
|
||||||
project.resources.each do |resource|
|
|
||||||
c = resource.translation(code).content
|
|
||||||
file_name = "#{dir_name}/#{resource.name}"
|
|
||||||
begin
|
|
||||||
completed = resource.stats(code).completed
|
|
||||||
rescue Transifex::NotFound
|
|
||||||
puts "#{code} not found."
|
|
||||||
next
|
|
||||||
end
|
|
||||||
has_content ||= completed != "0%"
|
|
||||||
puts "Writing resource #{file_name}, #{completed} complete."
|
|
||||||
File.open(file_name, 'w') { |file| file.write(c) }
|
|
||||||
end
|
|
||||||
if !has_content
|
|
||||||
puts "Locale #{code} has no content, deleting."
|
|
||||||
FileUtils.rm_rf(dir_name)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,2 +0,0 @@
|
||||||
ruby pull_locales.rb
|
|
||||||
python pull_locales_postprocess.py
|
|
|
@ -1,45 +0,0 @@
|
||||||
#! python2
|
|
||||||
import io, os, json, re
|
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
with io.open('../_locales/en/messages.json', 'r', encoding='utf-8') as f:
|
|
||||||
items = json.load(f).items()
|
|
||||||
english = [(k, v['message']) for k, v in items if 'message' in v]
|
|
||||||
english_placeholders = [(k, v['placeholders']) for k,v in items
|
|
||||||
if 'placeholders' in v]
|
|
||||||
|
|
||||||
for locale_name in os.listdir('../_locales'):
|
|
||||||
if locale_name == 'en':
|
|
||||||
continue
|
|
||||||
if not re.match(r'^\w{2}(_\w{2,3})?$', locale_name):
|
|
||||||
print('Skipped %s: not a locale dir' % locale_name)
|
|
||||||
continue
|
|
||||||
loc_path = '../_locales/' + locale_name + '/messages.json'
|
|
||||||
with io.open(loc_path, 'r+', encoding='utf-8') as f:
|
|
||||||
loc = json.load(f, object_pairs_hook=OrderedDict)
|
|
||||||
|
|
||||||
deduplicated = 0
|
|
||||||
for msgId, message in english:
|
|
||||||
if msgId in loc and loc[msgId].get('message', '') == message:
|
|
||||||
del loc[msgId]
|
|
||||||
deduplicated += 1
|
|
||||||
|
|
||||||
changed = 0
|
|
||||||
for msgId, placeholder in english_placeholders:
|
|
||||||
if msgId in loc and cmp(placeholder, loc[msgId].get('placeholders', None)) != 0:
|
|
||||||
loc[msgId]['placeholders'] = placeholder
|
|
||||||
changed += 1
|
|
||||||
|
|
||||||
if deduplicated > 0 or changed > 0:
|
|
||||||
f.seek(0)
|
|
||||||
json_str = json.dumps(loc, indent=1, ensure_ascii=False,
|
|
||||||
separators=(',', ': '), encoding='utf-8')
|
|
||||||
json_tabs = re.sub(r'^\s+', lambda s: s.group(0).replace(' ', '\t'),
|
|
||||||
json_str, flags=re.MULTILINE)
|
|
||||||
f.write(json_tabs)
|
|
||||||
f.truncate()
|
|
||||||
print('%s: %d deduplicated%s' % (
|
|
||||||
locale_name,
|
|
||||||
deduplicated,
|
|
||||||
', %d placeholder(s) added' % changed if changed else ''
|
|
||||||
))
|
|
Loading…
Reference in New Issue
Block a user