Skip to content

Instantly share code, notes, and snippets.

@binho
Last active September 22, 2016 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binho/988c2bf096e2b0a00e73407d9be9d835 to your computer and use it in GitHub Desktop.
Save binho/988c2bf096e2b0a00e73407d9be9d835 to your computer and use it in GitHub Desktop.
Localization Report
#!/usr/bin/python
# -*- coding: utf-8 -*-
import fnmatch
import sys
import os
num_strings_base = 0
strings_on_base = []
num_strings_current_file = 0
strings_on_current_file = []
report_lines = []
print '\n ⚠️ Note: We do not consider empty lines and comments from strings files! ⚠️\n'
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, '*.strings'):
path = os.path.join(root, filename)
# Ignore storyboard files and launch screen for now
if 'Storyboard' in path or 'LaunchScreen' in path:
continue
# Is base file?
if 'Base' in path:
with open(path) as base_file:
lines = base_file.readlines()
for line in lines:
line_without_jump = line.replace("\n", "")
if not line_without_jump.startswith('//') and line_without_jump.strip() != "":
num_strings_base = num_strings_base + 1
strings_on_base.append(line_without_jump.split('=')[0].replace('"', '').strip())
print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
print '✅ Base file ✅'
print 'Path: ', path
print 'Number of lines: ', num_strings_base
print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n'
else:
num_strings_current_file = 0
strings_on_current_file = []
# All other files
with open(path) as other_file:
lines = other_file.readlines()
for line in lines:
line_without_jump = line.replace("\n", "")
if not line_without_jump.startswith('//') and line_without_jump.strip() != "":
num_strings_current_file = num_strings_current_file + 1
strings_on_current_file.append(line_without_jump.split('=')[0].replace('"', '').strip())
report_lines.append({'file': path, 'number of lines': str(num_strings_current_file)})
if num_strings_current_file != num_strings_base:
missing_strings_sorted = sorted(set(strings_on_base) - set(strings_on_current_file))
print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
print '👎🏽 Current file: ' + path + ' 😓'
print 'Number of lines in this file: ', num_strings_current_file
print 'Number of lines expected (base file): ', num_strings_base
print 'Rows NOT found in this file: ', ', '.join(missing_strings_sorted)
print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n'
print '🖨 Printing number of lines on each file:'
for report_line in report_lines:
print report_line
print ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment