是否有工具来区分/合并/排序可本地化的字符串文件?

时间:2021-06-23 00:28:49

Localizable strings file which are used for Apple/iPhone apps localization have the following format:

用于Apple / iPhone应用程序本地化的可本地化字符串文件具有以下格式:

/* COMMENT */
"KEY" = "VALUE"

Note that KEY is unique in a given strings file.
COMMENT is optional however it can help the translator with some additional info.

请注意,KEY在给定的字符串文件中是唯一的。 COMMENT是可选的,但它可以帮助翻译者提供一些额外的信息。

Example:

例:

/* Menu item to make the current document plain text */
"Make Plain Text" = "Make Plain Text";
/* Menu item to make the current document rich text */
"Make Rich Text" = "Make Rich Text";

I would like to diff/merge two strings files and optionally sort that kind of files. It would be great if the comments would be kept while doing these operations.

我想差异/合并两个字符串文件,并可选择排序那种文件。如果在进行这些操作时保留评论,那将是很好的。

The format is quite simple and I could write let's say a python script to do that, but if somebody has already done that, I prefer not reinveting the wheel ;)

格式非常简单,我可以写一个让我们说一个python脚本来做到这一点,但如果有人已经这样做了,我宁愿不重新启动方向盘;)

Do you know a tool that can manipulate strings file?

你知道一个可以操作字符串文件的工具吗?

7 个解决方案

#1


26  

I was desperate to find a decent way to manages Localized.strings during development, when there are new strings added to the code and you don't want to manually manage all the files.

我迫切希望找到一种在开发过程中管理Localized.strings的好方法,当代码中添加了新的字符串并且您不想手动管理所有文件时。

I found Localization Manager that does this quite well. It has a nonexistent documentation, but comes with a separate program for the translators. It imports your strings, keeps track of changes and exports the needed Localization.strings files back to your project.

我发现Localization Manager可以很好地完成这项工作。它有一个不存在的文档,但为翻译人员提供了一个单独的程序。它导入您的字符串,跟踪更改并将所需的Localization.strings文件导出回您的项目。

Up till now it seems to be freeware.

到目前为止它似乎是免费软件。

#2


6  

Like I said in this post, I recently found a free app called Localizable Strings Merge on the Mac App Store. It does exactly what you ask, even the sorting/beautification. And it is free. Hope it helps.

就像我在这篇文章中所说,我最近在Mac App Store上找到了一个名为Localizable Strings Merge的免费应用程序。它完全符合您的要求,甚至是分类/美化。它是免费的。希望能帮助到你。

#3


2  

I found this tool from the Three20 project:

我从Three20项目中找到了这个工具:

http://github.com/facebook/three20/blob/master/diffstrings.py

http://github.com/facebook/three20/blob/master/diffstrings.py

It answers my initial need in different way of what I had imagined:
it can diff between the main locale and the other locales to see what needs translating in each other locale. And then merge back the translated strings.

它以我想象的不同方式回答了我的初始需求:它可以在主要语言环境和其他语言环境之间进行区分,以查看需要在每个其他语言环境中进行翻译的内容。然后合并回翻译的字符串。

Note that it outputs xml files to give to the translators.

请注意,它输出xml文件以提供给翻译人员。

#4


0  

Ugly but works

丑陋但有效

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        NSString* f1 = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
        NSString* f2 = [NSString stringWithCString:argv[2] encoding:NSUTF8StringEncoding];

        //

        NSLog(@" Comparing %@ to %@\n", f1, f2);

        //

        NSError* error;
        if ( [f1 hasPrefix:@"~"] ) {
            f1 = [f1 stringByReplacingOccurrencesOfString:@"~" withString:NSHomeDirectory()];
        }
        if ( [f2 hasPrefix:@"~"] ) {
            f2 = [f2 stringByReplacingOccurrencesOfString:@"~" withString:NSHomeDirectory()];
        }

        NSStringEncoding encoding;
        NSString* f1Content = [NSString stringWithContentsOfFile:f1 usedEncoding:&encoding error:&error];
        NSString* f2Content = [NSString stringWithContentsOfFile:f2 usedEncoding:&encoding error:&error];

        //

        NSArray* f1Strings = [f1Content componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
        NSArray* f2Strings = [f2Content componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

        for (NSString* keyString in f1Strings) {
            NSString* trimKey = [keyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
            if ( !trimKey || [trimKey isEqualToString:@""] )
                continue;

            NSString* key = [keyString componentsSeparatedByString:@" = "][0];

            BOOL found = NO;
            for (NSString* keyString2 in f2Strings) {
                if ( [keyString2 hasPrefix:key] ) {
                    found = YES;
                    break;
                }
            }

            if ( !found ) {
                printf("%s\n\n", [keyString UTF8String]);
            }
        }
    }
    return 0;
}

#5


0  

https://github.com/luckytianyiyan/TyStrings

https://github.com/luckytianyiyan/TyStrings

$ tystrings diff diff1.strings diff2.strings

>>> Parsing File1 Reference...
>>> Parsing File2 Reference...
>>> Comparing...
+----+---------+---------+-------------+---------+
|    | File1   | File2   | Key         | Value   |
|----+---------+---------+-------------+---------|
| +  | 2       |         | diff.test.0 | Test0   |
| -  |         | 2       | diff.test.0 | Test    |
| -  |         | 5       | diff.test.4 | Test4   |
| +  | 8       |         | diff.test.2 | Test2   |
| -  |         | 11      | diff.test.3 | Test3   |
+----+---------+---------+-------------+---------+

#6


-2  

Use TextWrangler to open both the string files and merge them.

使用TextWrangler打开两个字符串文件并合并它们。

It's easy and free too!

这很容易也是免费的!

You can see here what happens when you

你可以在这里看到你发生了什么

  1. Open the string files in TextWrangler
  2. 在TextWrangler中打开字符串文件
  3. Select both and then click on compare
  4. 选择两者,然后单击比较

Below is the screenshot of how it looks:

下面是它的外观截图:

是否有工具来区分/合并/排序可本地化的字符串文件?

#7


-3  

You can try /Developer/Applications/Utilities/FileMerge.app. That's always a good start. Also, you should try genstrings.

您可以尝试/Developer/Applications/Utilities/FileMerge.app。这总是一个好的开始。此外,你应该尝试genstrings。

#1


26  

I was desperate to find a decent way to manages Localized.strings during development, when there are new strings added to the code and you don't want to manually manage all the files.

我迫切希望找到一种在开发过程中管理Localized.strings的好方法,当代码中添加了新的字符串并且您不想手动管理所有文件时。

I found Localization Manager that does this quite well. It has a nonexistent documentation, but comes with a separate program for the translators. It imports your strings, keeps track of changes and exports the needed Localization.strings files back to your project.

我发现Localization Manager可以很好地完成这项工作。它有一个不存在的文档,但为翻译人员提供了一个单独的程序。它导入您的字符串,跟踪更改并将所需的Localization.strings文件导出回您的项目。

Up till now it seems to be freeware.

到目前为止它似乎是免费软件。

#2


6  

Like I said in this post, I recently found a free app called Localizable Strings Merge on the Mac App Store. It does exactly what you ask, even the sorting/beautification. And it is free. Hope it helps.

就像我在这篇文章中所说,我最近在Mac App Store上找到了一个名为Localizable Strings Merge的免费应用程序。它完全符合您的要求,甚至是分类/美化。它是免费的。希望能帮助到你。

#3


2  

I found this tool from the Three20 project:

我从Three20项目中找到了这个工具:

http://github.com/facebook/three20/blob/master/diffstrings.py

http://github.com/facebook/three20/blob/master/diffstrings.py

It answers my initial need in different way of what I had imagined:
it can diff between the main locale and the other locales to see what needs translating in each other locale. And then merge back the translated strings.

它以我想象的不同方式回答了我的初始需求:它可以在主要语言环境和其他语言环境之间进行区分,以查看需要在每个其他语言环境中进行翻译的内容。然后合并回翻译的字符串。

Note that it outputs xml files to give to the translators.

请注意,它输出xml文件以提供给翻译人员。

#4


0  

Ugly but works

丑陋但有效

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        NSString* f1 = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
        NSString* f2 = [NSString stringWithCString:argv[2] encoding:NSUTF8StringEncoding];

        //

        NSLog(@" Comparing %@ to %@\n", f1, f2);

        //

        NSError* error;
        if ( [f1 hasPrefix:@"~"] ) {
            f1 = [f1 stringByReplacingOccurrencesOfString:@"~" withString:NSHomeDirectory()];
        }
        if ( [f2 hasPrefix:@"~"] ) {
            f2 = [f2 stringByReplacingOccurrencesOfString:@"~" withString:NSHomeDirectory()];
        }

        NSStringEncoding encoding;
        NSString* f1Content = [NSString stringWithContentsOfFile:f1 usedEncoding:&encoding error:&error];
        NSString* f2Content = [NSString stringWithContentsOfFile:f2 usedEncoding:&encoding error:&error];

        //

        NSArray* f1Strings = [f1Content componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
        NSArray* f2Strings = [f2Content componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

        for (NSString* keyString in f1Strings) {
            NSString* trimKey = [keyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
            if ( !trimKey || [trimKey isEqualToString:@""] )
                continue;

            NSString* key = [keyString componentsSeparatedByString:@" = "][0];

            BOOL found = NO;
            for (NSString* keyString2 in f2Strings) {
                if ( [keyString2 hasPrefix:key] ) {
                    found = YES;
                    break;
                }
            }

            if ( !found ) {
                printf("%s\n\n", [keyString UTF8String]);
            }
        }
    }
    return 0;
}

#5


0  

https://github.com/luckytianyiyan/TyStrings

https://github.com/luckytianyiyan/TyStrings

$ tystrings diff diff1.strings diff2.strings

>>> Parsing File1 Reference...
>>> Parsing File2 Reference...
>>> Comparing...
+----+---------+---------+-------------+---------+
|    | File1   | File2   | Key         | Value   |
|----+---------+---------+-------------+---------|
| +  | 2       |         | diff.test.0 | Test0   |
| -  |         | 2       | diff.test.0 | Test    |
| -  |         | 5       | diff.test.4 | Test4   |
| +  | 8       |         | diff.test.2 | Test2   |
| -  |         | 11      | diff.test.3 | Test3   |
+----+---------+---------+-------------+---------+

#6


-2  

Use TextWrangler to open both the string files and merge them.

使用TextWrangler打开两个字符串文件并合并它们。

It's easy and free too!

这很容易也是免费的!

You can see here what happens when you

你可以在这里看到你发生了什么

  1. Open the string files in TextWrangler
  2. 在TextWrangler中打开字符串文件
  3. Select both and then click on compare
  4. 选择两者,然后单击比较

Below is the screenshot of how it looks:

下面是它的外观截图:

是否有工具来区分/合并/排序可本地化的字符串文件?

#7


-3  

You can try /Developer/Applications/Utilities/FileMerge.app. That's always a good start. Also, you should try genstrings.

您可以尝试/Developer/Applications/Utilities/FileMerge.app。这总是一个好的开始。此外,你应该尝试genstrings。