在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):JiriTrecak/Laurine开源软件地址(OpenSource Url):https://github.com/JiriTrecak/Laurine开源编程语言(OpenSource Language):Swift 97.7%开源软件介绍(OpenSource Introduction):
LaurineLocalization code generator written (with love) for Swift, intended to end the constant problems that localizations present developers.
Do I need it? (Yes, you do)Laurine is a clever Swift script that scans your localization file and generates structured, high-performance code out of it (in both ObjC or Swift, your call), thereby making the usage of localization strings much easier and safer. The great thing is that by removing magical strings from your code, the compiler can actually tell you when you forget to make changes (and where), if your localization file changes. It also introduces type checking for strings that contain runtime format specifiers ( Laurine requires Swift to run and can be used from the command line as well as from a build script (recommended). Laurine uses CommandLine to parse command line arguemnts: no extra configuration is needed. What do I get?Once you run Laurine, the output will be one .swift or .m file containing a Variables For each string that does not contain any special characters, a property is generated. For example: "PROFILE_PHONE_NUMBER" = "Your phone number!" can be then used like this: self.labelToLocalize.text = Localizations.ProfilePhoneNumber in Xcode, autocomplete is actually, for once, really helpful! Madness. Methods If your localization string has runtime format specifiers, it is generated as a method instead. Laurine detects the format specifiers and generates a proper method header from that definition. There is no limit to how many of them you have. For example: "PROFILE_INFO" = "I am %@, I am %d years old and %.2fm in height!" can be then used like this: self.labelToLocalize.text = Localizations.ProfileInfo("Jiri", 25, 1.75) Once again, Xcode autocomplete for the win! Insanity. Swift support Swift-written application is recommended Laurine usecase. Internally, it uses nested structures to make your life much easier. Also, it is extremely performant and will have no impact on your current codebase. ObjC support Objective-C is supported from v0.2 as well. Because of the way the code is generated, you can write just the same code as you would in Swift, using dot notation to access each next element. For example: NSString *text = Localizations.ProfileInfo("Jiri", 25, 1.75) This produces exactly the same result as you would get in Swift and is recommended. Nested StructuresIt is best practice to make the keys as descriptive and structured as possible. Laurine takes advantage of that to generate nested structures rather than overly long key names. For example: "PROFILE-NAVIGATION_BAR-ITEMS-DONE" = "Done" // -c -d -
"PROFILE.NAVIGATION_BAR.ITEMS.DONE" = "Done" // -c -d . Is actually converted to: self.labelToLocalize.text = Localizations.Profile.NavigationBar.Items.Done This way, you can easily traverse through thousands of strings without even thinking about it (obviously, how you actually group your strings is up to you). You can use Use Note: Language-specific keywords (such as Swift: UsageLaurine uses script parameters to change the way how output is generated. Currently, the following is supported:
Command line If you wish to generate output just once, run following from terminal in the directory where you have the script downloaded:
or, alternatively, if you downloaded it through Brew:
Build script The recommended way to use Laurine is to create a "Run Script" Build Phase (Xcode > Project > Targets > Your build target > Build Phases > New Run Script Phase). This way, Laurine will be executed before each build and will ensure the integrity of your translations. Be sure to put the script before the "Compile Sources" phase, as it has to generate the code first, before it can be used anywhere else. For convenience, you can just copy the following, and change the configuration appropriately. set -x
# Get base path to project
BASE_PATH="$PROJECT_DIR/$PROJECT_NAME"
#--------- START OF YOUR CONFIGURATION (change Path_To_.. to fit)
# Get path to Laurine Generator script
LAURINE_PATH="$BASE_PATH/Path_To_Generator/LaurineGenerator.swift"
# Get path to main localization file (usually english).
SOURCE_PATH="$BASE_PATH/Path_To_Base_Localization/Localizable.strings"
# Get path to output. If you use ObjC version of output, set implementation file (.m), as header will be generated automatically
OUTPUT_PATH="$BASE_PATH/Path_To_Output/Localizations.swift"
#--------- END OF YOUR CONFIGURATION
# Add permission to generator for script execution
chmod 755 "$LAURINE_PATH"
# Actually generate output. -- CUSTOMIZE -- parameters to your needs (see documentation).
# Will only re-generate script if something changed
if [ "$OUTPUT_PATH" -ot "$SOURCE_PATH" ]; then
"$LAURINE_PATH" -i "$SOURCE_PATH" -o "$OUTPUT_PATH"
fi
InstallationBrew Laurine does not require installation. For your convenience, you can make it easily accessible from
Now you can just run it from everywhere:
GIT You can also just clone it wherever you desire:
Download! Yes, you can just download the script itself from this repository, it does not need anything else. Supported FeaturesLaurine should suit most of developers, because it covers all the basic stuff. That being said, there are still things missing to have full coverage of what localizations have to offer. Here is the full list of features that will Laurine contain once it is complete:
ContributeI will gladly accept Pull Requests (and I encourage you to do so). If you encounter any bug or you have enhancement that you would like to see, please open an issue. Please make sure you target your PR against Development branch. I'd also like to make round of applause to Marcin Krzyżanowski for his Natalie Generator, which heavily inspired this project by his approach. Hope we meet for beer one day! More libraries, same awesomenessIf you liked it, check out my other library - Warp, that will help you with development of your data models. Contact meOr, if you would like to know me better, check out my portfolio. ##Licence The MIT License (MIT) Copyright (c) 2015 Jiří Třečák Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论