Skip to content

Commit bfa8458

Browse files
committed
Fix string generate/merge bug for ib files
1 parent 5e0a752 commit bfa8458

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

OneSkyPlugin.xcplugin/Contents/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<key>CFBundlePackageType</key>
1818
<string>BNDL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.4.9</string>
20+
<string>1.5.0</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>1.4.9</string>
24+
<string>1.5.0</string>
2525
<key>DTCompiler</key>
2626
<string>com.apple.compilers.llvm.clang.1_0</string>
2727
<key>DTPlatformBuild</key>
80 Bytes
Binary file not shown.

OneSkyPlugin.xcplugin/Contents/Resources/merge_files.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ def __str__(self):
573573
ENCODINGS = ['utf16', 'utf8']
574574

575575

576-
def merge_strings(old_strings, new_strings, keep_comment=False):
576+
def merge_strings(old_strings, new_strings, keep_comment=False, replace_value=False):
577577
'''Merges two dictionarys, one with the old strings and one with the new
578578
strings.
579579
Old strings keep their value but their comment will be updated. Only if
@@ -590,12 +590,16 @@ def merge_strings(old_strings, new_strings, keep_comment=False):
590590
591591
new_strings
592592
Dictionary with the new Strings
593-
593+
594594
keep_comment
595595
If True, the old comment will be kept. This is necessary for
596596
translating Storyboard files because they have generated comments
597-
which are not very helpfull
598-
597+
which are not very helpful
598+
599+
replace_value
600+
If True, the old value will be replaced. This is necessary for
601+
translating IB files because they are never `raw` strings
602+
599603
Returns
600604
601605
Merged Dictionary
@@ -650,7 +654,7 @@ def merge_strings(old_strings, new_strings, keep_comment=False):
650654
for key, old_string in old_strings.iteritems():
651655
if key in new_strings:
652656
new_string = new_strings[key]
653-
if old_string.is_raw():
657+
if old_string.is_raw() or replace_value:
654658
# if the old string is raw just take the new string
655659
if keep_comment:
656660
new_string.comment = old_string.comment
@@ -730,7 +734,7 @@ def sort_strings(strings):
730734
return values
731735

732736

733-
def merge_files(new_file_path, old_file_path, keep_comment=False):
737+
def merge_files(new_file_path, old_file_path, keep_comment=False, replace_value=False):
734738
'''Scans the Strings in both files, merges them together and writes the
735739
result to the old file
736740
@@ -745,7 +749,7 @@ def merge_files(new_file_path, old_file_path, keep_comment=False):
745749
new_strings = parse_file(new_file_path)
746750
logging.debug('Current File: {}'.format(old_file_path))
747751
old_strings = parse_file(old_file_path)
748-
final_strings = merge_strings(old_strings, new_strings, keep_comment)
752+
final_strings = merge_strings(old_strings, new_strings, keep_comment, replace_value)
749753
write_file(old_file_path, final_strings)
750754

751755

@@ -779,6 +783,24 @@ def main():
779783
default=False,
780784
help='Show debug messages'
781785
)
786+
787+
parser.add_option(
788+
'-r',
789+
'--replace_value',
790+
action='store_true',
791+
dest='replace_value',
792+
default=False,
793+
help='Force replace string values with ones in new file'
794+
)
795+
796+
parser.add_option(
797+
'-k',
798+
'--keep_comment',
799+
action='store_true',
800+
dest='keep_comment',
801+
default=True,
802+
help='Keep comment from the old string'
803+
)
782804

783805
(options, args) = parser.parse_args()
784806

@@ -788,7 +810,7 @@ def main():
788810
level=options.verbose and logging.DEBUG or logging.INFO
789811
)
790812

791-
merge_files(options.new_path, options.old_path, True)
813+
merge_files(options.new_path, options.old_path, options.keep_comment, options.replace_value)
792814
return 0
793815

794816
if __name__ == '__main__':

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This library lets you sync localizable string resources and translations with On
77
Installation
88
------------
99

10-
1. Download [`OneSkyPlugin.zip`](https://github.com/onesky/plugin-xcode/releases/download/1.4.9/OneSkyPlugin.zip) in the release tab and unzip the folder into `~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/`. If this is the first Plug-ins that you use in Xcode, the Plug-ins directory does not exist. In this case, creating the directory manually would do. Then, Relaunch Xcode.
10+
1. Download [`OneSkyPlugin.zip`](https://github.com/onesky/plugin-xcode/releases/download/1.5.0/OneSkyPlugin.zip) in the release tab and unzip the folder into `~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/`. If this is the first Plug-ins that you use in Xcode, the Plug-ins directory does not exist. In this case, creating the directory manually would do. Then, Relaunch Xcode.
1111
2. To uninstall, just remove the plugin from there (and restart Xcode) and the project property cache file in `~/Library/Application Support/OneSky/OneSkyProperties.plist`.
1212

1313
Project Settings

0 commit comments

Comments
 (0)