Rumpelstiltskin 0.1.5

Rumpelstiltskin 0.1.5

Christian BraunChristian维护。



  • Christian Braun

Rumpelstiltskin

Version Platform

Rumpelstiltskin会将您的本地化文件转换成以下样子

"Accessibility.Example1" = "Accessibility";
"Accessibility.ThumbnailImage" = "Thumbnail %d with name %@";

变成以下这样的swift结构体

struct Localizations {
    struct Accessibility {

        /// Base translation: Accessibility
        public static let Example1 = NSLocalizedString("Accessibility.Example1", tableName: nil, bundle: Bundle.main, value: "", comment: "")

        /// Base translation: Thumbnail %d with name %@
        public static func ThumbnailImage(value1: Int, _ value2: String) -> String {
            return String(format: NSLocalizedString("Accessibility.ThumbnailImage", tableName: nil, bundle: Bundle.main, value: "", comment: "")
            , value1, value2)
        }
    }
}

它被构建成Laurine - Storyboard Generator Script(不幸地在2017年停止维护的Storyboard生成脚本的)的直接替换品。

示例

要运行示例项目,请首先克隆仓库,然后从示例目录运行`pod install`。

要求

  • Swift 5.*

设置

在您的Xcode项目构建阶段中创建一个新的运行脚本阶段。

echo "Rumpelstiltskin begins to dance around fire"
# Get base path to project
BASE_PATH="$PROJECT_DIR/$PROJECT_NAME"

# Get path to Generator script
GENERATOR_PATH="${PODS_ROOT}/Rumpelstiltskin/main.swift"

# Get path to main localization file (usually english).
SOURCE_PATH="$BASE_PATH/SupportingFiles/Base.lproj/Localizable.strings"

OUTPUT_PATH="$BASE_PATH/Vendor/Localizations.swift"

# Add permission to generator for script execution
chmod 755 "$GENERATOR_PATH"

# Will only re-generate script if something changed
if [ "$SOURCE_PATH" -nt "$OUTPUT_PATH" ]; then
"$GENERATOR_PATH" "$SOURCE_PATH" "$OUTPUT_PATH"
echo "Regenerated strings structure"
fi

如果您第一次运行Rumpelstiltskin,您将需要将新生成的`Localizations.swift`文件添加到项目中。从那时起,每次更改`Localizable.strings`文件时,该文件都会自动更新。

用法

我们假设您已经在合适的位置放置了一个Localizable.strings文件。

通过使用点`.`分隔来生成嵌套结构

# Localizable.strings
"MainStructure.NestedStructure.ConcreteValue" = "This needs to be localized";
// Code
label.text = Localizations.MainStructure.NestedStructure.ConcreteValue

使用函数来构建字符串。(目前支持 Int、Float 和 String)

// %@: String, %d: Int, %f: float 
"Buttons.TextWithVariables" = "Awesome %@, press me %d times!";
// Code
label.text = Localizations.Buttons.TextWithVariables(value1: "App", value2: 10)

当前不支持

  • 多行字符串:请使用 \n 在您的 Localizable.strings 文件中格式化字符串。

安装

Rumpelstiltskin通过CocoaPods提供。要安装它,只需在Podfile中添加以下行:

pod 'Rumpelstiltskin'

作者

Christian Braun

许可证

Rumpelstiltskin采用MIT许可证。有关更多详细信息,请参阅LICENSE文件。