-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1e55b17
Showing
6 changed files
with
373 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Xcode | ||
.DS_Store | ||
*/build/* | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
profile | ||
*.moved-aside | ||
DerivedData | ||
.idea/ | ||
*.hmap | ||
*.xccheckout | ||
|
||
#CocoaPods | ||
Pods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# | ||
# Be sure to run `pod spec lint AMLocalized.podspec' to ensure this is a | ||
# valid spec and to remove all comments including this before submitting the spec. | ||
# | ||
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html | ||
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ | ||
# | ||
|
||
Pod::Spec.new do |s| | ||
|
||
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# These will help people to find your library, and whilst it | ||
# can feel like a chore to fill in it's definitely to your advantage. The | ||
# summary should be tweet-length, and the description more in depth. | ||
# | ||
|
||
s.name = "AMLocalized" | ||
s.version = "0.1" | ||
s.summary = "Localization system that supports changing the language at run-time and adds support for multiple languages" | ||
|
||
# This description is used to generate tags and improve search results. | ||
# * Think: What does it do? Why did you write it? What is the focus? | ||
# * Try to keep it short, snappy and to the point. | ||
# * Write the description between the DESC delimiters below. | ||
# * Finally, don't worry about the indent, CocoaPods strips it! | ||
s.description = <<-DESC | ||
AMLocalized is | ||
- fully compatible with Xcode implementation: you don't have to change your code if you don't want to | ||
- supports run-time change of the app language! | ||
- adds support for multiple language that the iOS implementation is missing (like Esperanto, Catalá, Klingon and more) | ||
Usage: | ||
1. LocalizationSetLanguage("language") // where "language" string should match the name of the .strings file -> language.strings | ||
2. AMLocalizedString("tag", "alternative") // tag is the key, alternative is, well, the alternative if the tag is not found in the .strings file | ||
Extra: | ||
- LocalizationReset // to reset to default values | ||
- LocalizationGetLanguage // to get the current language used | ||
DESC | ||
|
||
s.homepage = "http://aggressive-mediocrity.blogspot.de/2010/03/custom-localization-system-for-your.html" | ||
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" | ||
|
||
|
||
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# Licensing your code is important. See http://choosealicense.com for more info. | ||
# CocoaPods will detect a license file if there is a named LICENSE* | ||
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. | ||
# | ||
|
||
# s.license = "MIT" | ||
s.license = { :type => "MIT", :file => "LICENSE" } | ||
|
||
|
||
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# Specify the authors of the library, with email addresses. Email addresses | ||
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also | ||
# accepts just a name if you'd rather not provide an email address. | ||
# | ||
# Specify a social_media_url where others can refer to, for example a twitter | ||
# profile URL. | ||
# | ||
|
||
s.author = "Juan Albero Sanchis" | ||
# Or just: s.author = "" | ||
# s.authors = { "" => "" } | ||
# s.social_media_url = "http://twitter.com/" | ||
|
||
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# If this Pod runs only on iOS or OS X, then specify the platform and | ||
# the deployment target. You can optionally include the target after the platform. | ||
# | ||
|
||
s.platform = :ios | ||
# s.platform = :ios, "5.0" | ||
|
||
# When using multiple platforms | ||
# s.ios.deployment_target = "5.0" | ||
# s.osx.deployment_target = "10.7" | ||
# s.watchos.deployment_target = "2.0" | ||
# s.tvos.deployment_target = "9.0" | ||
|
||
|
||
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# Specify the location from where the source should be retrieved. | ||
# Supports git, hg, bzr, svn and HTTP. | ||
# | ||
|
||
s.source = { :git => "https://github.com/tagyro/AMLocalizedString.git", :tag => "0.1" } | ||
|
||
|
||
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# CocoaPods is smart about how it includes source code. For source files | ||
# giving a folder will include any swift, h, m, mm, c & cpp files. | ||
# For header files it will include any header in the folder. | ||
# Not including the public_header_files will make all headers public. | ||
# | ||
|
||
s.source_files = "*.{h,m}" | ||
s.exclude_files = "Classes/Exclude" | ||
|
||
# s.public_header_files = "*.h" | ||
|
||
|
||
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# A list of resources included with the Pod. These are copied into the | ||
# target bundle with a build phase script. Anything else will be cleaned. | ||
# You can preserve files from being cleaned, please don't preserve | ||
# non-essential files like tests, examples and documentation. | ||
# | ||
|
||
# s.resource = "icon.png" | ||
# s.resources = "Resources/*.png" | ||
|
||
# s.preserve_paths = "FilesToSave", "MoreFilesToSave" | ||
|
||
|
||
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# Link your library with frameworks, or libraries. Libraries do not include | ||
# the lib prefix of their name. | ||
# | ||
|
||
# s.framework = "SomeFramework" | ||
# s.frameworks = "SomeFramework", "AnotherFramework" | ||
|
||
# s.library = "iconv" | ||
# s.libraries = "iconv", "xml2" | ||
|
||
|
||
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# If your library depends on compiler flags you can set them in the xcconfig hash | ||
# where they will only apply to your library. If you depend on other Podspecs | ||
# you can include multiple dependencies to ensure it works. | ||
|
||
# s.requires_arc = true | ||
|
||
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } | ||
# s.dependency "JSONKit", "~> 1.4" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright (c) 2010-2015 Juan Albero Sanchis | ||
|
||
|
||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// LocalizationSystem.h | ||
// Battle of Puppets | ||
// | ||
// Created by Juan Albero Sanchis on 27/02/10. | ||
// Copyright Aggressive Mediocrity 2010. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#define AMLocalizedString(key, comment) \ | ||
[[LocalizationSystem sharedLocalSystem] localizedStringForKey:(key) value:(comment)] | ||
|
||
#define LocalizationSetLanguage(language) \ | ||
[[LocalizationSystem sharedLocalSystem] setLanguage:(language)] | ||
|
||
#define LocalizationGetLanguage \ | ||
[[LocalizationSystem sharedLocalSystem] getLanguage] | ||
|
||
#define LocalizationReset \ | ||
[[LocalizationSystem sharedLocalSystem] resetLocalization] | ||
|
||
@interface LocalizationSystem : NSObject { | ||
NSString *language; | ||
} | ||
|
||
// you really shouldn't care about this functions and use the MACROS | ||
+ (LocalizationSystem *)sharedLocalSystem; | ||
|
||
//gets the string localized | ||
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)comment; | ||
|
||
//sets the language | ||
- (void) setLanguage:(NSString*) language; | ||
|
||
//gets the current language | ||
- (NSString*) getLanguage; | ||
|
||
//resets this system. | ||
- (void) resetLocalization; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// | ||
// LocalizationSystem.m | ||
// Battle of Puppets | ||
// | ||
// Created by Juan Albero Sanchis on 27/02/10. | ||
// Copyright Aggressive Mediocrity 2010. All rights reserved. | ||
// | ||
|
||
#import "LocalizationSystem.h" | ||
|
||
@implementation LocalizationSystem | ||
|
||
//Singleton instance | ||
static LocalizationSystem *_sharedLocalSystem = nil; | ||
|
||
//Current application bungle to get the languages. | ||
static NSBundle *bundle = nil; | ||
|
||
+(LocalizationSystem *)sharedLocalSystem { | ||
static dispatch_once_t once; | ||
dispatch_once(&once, ^ { | ||
_sharedLocalSystem = [[super allocWithZone:nil] init]; | ||
[_sharedLocalSystem setLanguage:[_sharedLocalSystem getLanguage]]; | ||
}); | ||
return _sharedLocalSystem; | ||
} | ||
|
||
- (id)init { | ||
if (_sharedLocalSystem) { | ||
return _sharedLocalSystem; | ||
} | ||
if (self = [super init]) { | ||
|
||
// | ||
} | ||
return self; | ||
} | ||
|
||
- (id)copy { | ||
return [[self class] sharedLocalSystem]; | ||
} | ||
|
||
+ (id)allocWithZone:(NSZone *)zone { | ||
return [self sharedLocalSystem]; | ||
} | ||
|
||
+(id)alloc | ||
{ | ||
@synchronized([LocalizationSystem class]) | ||
{ | ||
NSAssert(_sharedLocalSystem == nil, @"Attempted to allocate a second instance of a singleton."); | ||
_sharedLocalSystem = [super alloc]; | ||
return _sharedLocalSystem; | ||
} | ||
// to avoid compiler warning | ||
return nil; | ||
} | ||
|
||
// Gets the current localized string as in NSLocalizedString. | ||
// | ||
// example calls: | ||
// AMLocalizedString(@"Text to localize",@"Alternative text, in case hte other is not find"); | ||
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)comment | ||
{ | ||
if (!bundle) { | ||
bundle = nil; | ||
} | ||
return [bundle localizedStringForKey:key value:comment table:nil]; | ||
} | ||
|
||
|
||
// Sets the desired language of the ones you have. | ||
// example calls: | ||
// LocalizationSetLanguage(@"Italian"); | ||
// LocalizationSetLanguage(@"German"); | ||
// LocalizationSetLanguage(@"Spanish"); | ||
// | ||
// If this function is not called it will use the default OS language. | ||
// If the language does not exists y returns the default OS language. | ||
- (void) setLanguage:(NSString*) l{ | ||
#ifdef DEBUG | ||
NSLog(@"preferredLang: %@", l); | ||
#endif | ||
|
||
NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ]; | ||
|
||
if ([l isEqualToString:@"en"]) { | ||
path = [[ NSBundle mainBundle ] pathForResource:@"Base" ofType:@"lproj" ]; | ||
} | ||
if (path == nil) { | ||
//in case the language does not exists | ||
[self resetLocalization]; | ||
} | ||
else { | ||
bundle = [NSBundle bundleWithPath:path]; | ||
// | ||
[[NSUserDefaults standardUserDefaults] setObject:@[l] forKey:@"AppleLanguages"]; | ||
// | ||
[[NSUserDefaults standardUserDefaults] synchronize]; | ||
} | ||
} | ||
|
||
// Just gets the current setted up language. | ||
// returns "es","fr",... | ||
// | ||
// example call: | ||
// NSString * currentL = LocalizationGetLanguage; | ||
- (NSString*) getLanguage{ | ||
|
||
NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]; | ||
|
||
NSString *preferredLang = [languages objectAtIndex:0]; | ||
|
||
return preferredLang; | ||
} | ||
|
||
// Resets the localization system, so it uses the OS default language. | ||
// | ||
// example call: | ||
// LocalizationReset; | ||
- (void) resetLocalization | ||
{ | ||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"]; | ||
// | ||
[[NSUserDefaults standardUserDefaults] synchronize]; | ||
// | ||
NSString *path = [[NSBundle mainBundle] pathForResource:@"Base" ofType:@"lproj" ]; | ||
bundle = [NSBundle bundleWithPath:path]; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
AMLocalizedString | ||
================= | ||
|
||
####Copyright [AGGRESSIVE MEDIOCRITY](http://aggressive-mediocrity.blogspot.de/2010/03/custom-localization-system-for-your.html) |