Skip to content

Commit 1e55b17

Browse files
committed
Initial Cocoapods release
0 parents  commit 1e55b17

6 files changed

Lines changed: 373 additions & 0 deletions

File tree

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Xcode
2+
.DS_Store
3+
*/build/*
4+
*.pbxuser
5+
!default.pbxuser
6+
*.mode1v3
7+
!default.mode1v3
8+
*.mode2v3
9+
!default.mode2v3
10+
*.perspectivev3
11+
!default.perspectivev3
12+
xcuserdata
13+
profile
14+
*.moved-aside
15+
DerivedData
16+
.idea/
17+
*.hmap
18+
*.xccheckout
19+
20+
#CocoaPods
21+
Pods

AMLocalized.podspec

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#
2+
# Be sure to run `pod spec lint AMLocalized.podspec' to ensure this is a
3+
# valid spec and to remove all comments including this before submitting the spec.
4+
#
5+
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
6+
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
7+
#
8+
9+
Pod::Spec.new do |s|
10+
11+
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
12+
#
13+
# These will help people to find your library, and whilst it
14+
# can feel like a chore to fill in it's definitely to your advantage. The
15+
# summary should be tweet-length, and the description more in depth.
16+
#
17+
18+
s.name = "AMLocalized"
19+
s.version = "0.1"
20+
s.summary = "Localization system that supports changing the language at run-time and adds support for multiple languages"
21+
22+
# This description is used to generate tags and improve search results.
23+
# * Think: What does it do? Why did you write it? What is the focus?
24+
# * Try to keep it short, snappy and to the point.
25+
# * Write the description between the DESC delimiters below.
26+
# * Finally, don't worry about the indent, CocoaPods strips it!
27+
s.description = <<-DESC
28+
AMLocalized is
29+
- fully compatible with Xcode implementation: you don't have to change your code if you don't want to
30+
- supports run-time change of the app language!
31+
- adds support for multiple language that the iOS implementation is missing (like Esperanto, Catalá, Klingon and more)
32+
33+
Usage:
34+
1. LocalizationSetLanguage("language") // where "language" string should match the name of the .strings file -> language.strings
35+
2. AMLocalizedString("tag", "alternative") // tag is the key, alternative is, well, the alternative if the tag is not found in the .strings file
36+
37+
Extra:
38+
- LocalizationReset // to reset to default values
39+
- LocalizationGetLanguage // to get the current language used
40+
DESC
41+
42+
s.homepage = "http://aggressive-mediocrity.blogspot.de/2010/03/custom-localization-system-for-your.html"
43+
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
44+
45+
46+
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
47+
#
48+
# Licensing your code is important. See http://choosealicense.com for more info.
49+
# CocoaPods will detect a license file if there is a named LICENSE*
50+
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
51+
#
52+
53+
# s.license = "MIT"
54+
s.license = { :type => "MIT", :file => "LICENSE" }
55+
56+
57+
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
58+
#
59+
# Specify the authors of the library, with email addresses. Email addresses
60+
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
61+
# accepts just a name if you'd rather not provide an email address.
62+
#
63+
# Specify a social_media_url where others can refer to, for example a twitter
64+
# profile URL.
65+
#
66+
67+
s.author = "Juan Albero Sanchis"
68+
# Or just: s.author = ""
69+
# s.authors = { "" => "" }
70+
# s.social_media_url = "http://twitter.com/"
71+
72+
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
73+
#
74+
# If this Pod runs only on iOS or OS X, then specify the platform and
75+
# the deployment target. You can optionally include the target after the platform.
76+
#
77+
78+
s.platform = :ios
79+
# s.platform = :ios, "5.0"
80+
81+
# When using multiple platforms
82+
# s.ios.deployment_target = "5.0"
83+
# s.osx.deployment_target = "10.7"
84+
# s.watchos.deployment_target = "2.0"
85+
# s.tvos.deployment_target = "9.0"
86+
87+
88+
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
89+
#
90+
# Specify the location from where the source should be retrieved.
91+
# Supports git, hg, bzr, svn and HTTP.
92+
#
93+
94+
s.source = { :git => "https://github.com/tagyro/AMLocalizedString.git", :tag => "0.1" }
95+
96+
97+
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
98+
#
99+
# CocoaPods is smart about how it includes source code. For source files
100+
# giving a folder will include any swift, h, m, mm, c & cpp files.
101+
# For header files it will include any header in the folder.
102+
# Not including the public_header_files will make all headers public.
103+
#
104+
105+
s.source_files = "*.{h,m}"
106+
s.exclude_files = "Classes/Exclude"
107+
108+
# s.public_header_files = "*.h"
109+
110+
111+
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
112+
#
113+
# A list of resources included with the Pod. These are copied into the
114+
# target bundle with a build phase script. Anything else will be cleaned.
115+
# You can preserve files from being cleaned, please don't preserve
116+
# non-essential files like tests, examples and documentation.
117+
#
118+
119+
# s.resource = "icon.png"
120+
# s.resources = "Resources/*.png"
121+
122+
# s.preserve_paths = "FilesToSave", "MoreFilesToSave"
123+
124+
125+
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
126+
#
127+
# Link your library with frameworks, or libraries. Libraries do not include
128+
# the lib prefix of their name.
129+
#
130+
131+
# s.framework = "SomeFramework"
132+
# s.frameworks = "SomeFramework", "AnotherFramework"
133+
134+
# s.library = "iconv"
135+
# s.libraries = "iconv", "xml2"
136+
137+
138+
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
139+
#
140+
# If your library depends on compiler flags you can set them in the xcconfig hash
141+
# where they will only apply to your library. If you depend on other Podspecs
142+
# you can include multiple dependencies to ensure it works.
143+
144+
# s.requires_arc = true
145+
146+
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
147+
# s.dependency "JSONKit", "~> 1.4"
148+
149+
end

LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2010-2015 Juan Albero Sanchis
2+
3+
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.

LocalizationSystem.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// LocalizationSystem.h
3+
// Battle of Puppets
4+
//
5+
// Created by Juan Albero Sanchis on 27/02/10.
6+
// Copyright Aggressive Mediocrity 2010. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
#define AMLocalizedString(key, comment) \
12+
[[LocalizationSystem sharedLocalSystem] localizedStringForKey:(key) value:(comment)]
13+
14+
#define LocalizationSetLanguage(language) \
15+
[[LocalizationSystem sharedLocalSystem] setLanguage:(language)]
16+
17+
#define LocalizationGetLanguage \
18+
[[LocalizationSystem sharedLocalSystem] getLanguage]
19+
20+
#define LocalizationReset \
21+
[[LocalizationSystem sharedLocalSystem] resetLocalization]
22+
23+
@interface LocalizationSystem : NSObject {
24+
NSString *language;
25+
}
26+
27+
// you really shouldn't care about this functions and use the MACROS
28+
+ (LocalizationSystem *)sharedLocalSystem;
29+
30+
//gets the string localized
31+
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)comment;
32+
33+
//sets the language
34+
- (void) setLanguage:(NSString*) language;
35+
36+
//gets the current language
37+
- (NSString*) getLanguage;
38+
39+
//resets this system.
40+
- (void) resetLocalization;
41+
42+
@end

LocalizationSystem.m

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
//
2+
// LocalizationSystem.m
3+
// Battle of Puppets
4+
//
5+
// Created by Juan Albero Sanchis on 27/02/10.
6+
// Copyright Aggressive Mediocrity 2010. All rights reserved.
7+
//
8+
9+
#import "LocalizationSystem.h"
10+
11+
@implementation LocalizationSystem
12+
13+
//Singleton instance
14+
static LocalizationSystem *_sharedLocalSystem = nil;
15+
16+
//Current application bungle to get the languages.
17+
static NSBundle *bundle = nil;
18+
19+
+(LocalizationSystem *)sharedLocalSystem {
20+
static dispatch_once_t once;
21+
dispatch_once(&once, ^ {
22+
_sharedLocalSystem = [[super allocWithZone:nil] init];
23+
[_sharedLocalSystem setLanguage:[_sharedLocalSystem getLanguage]];
24+
});
25+
return _sharedLocalSystem;
26+
}
27+
28+
- (id)init {
29+
if (_sharedLocalSystem) {
30+
return _sharedLocalSystem;
31+
}
32+
if (self = [super init]) {
33+
34+
//
35+
}
36+
return self;
37+
}
38+
39+
- (id)copy {
40+
return [[self class] sharedLocalSystem];
41+
}
42+
43+
+ (id)allocWithZone:(NSZone *)zone {
44+
return [self sharedLocalSystem];
45+
}
46+
47+
+(id)alloc
48+
{
49+
@synchronized([LocalizationSystem class])
50+
{
51+
NSAssert(_sharedLocalSystem == nil, @"Attempted to allocate a second instance of a singleton.");
52+
_sharedLocalSystem = [super alloc];
53+
return _sharedLocalSystem;
54+
}
55+
// to avoid compiler warning
56+
return nil;
57+
}
58+
59+
// Gets the current localized string as in NSLocalizedString.
60+
//
61+
// example calls:
62+
// AMLocalizedString(@"Text to localize",@"Alternative text, in case hte other is not find");
63+
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)comment
64+
{
65+
if (!bundle) {
66+
bundle = nil;
67+
}
68+
return [bundle localizedStringForKey:key value:comment table:nil];
69+
}
70+
71+
72+
// Sets the desired language of the ones you have.
73+
// example calls:
74+
// LocalizationSetLanguage(@"Italian");
75+
// LocalizationSetLanguage(@"German");
76+
// LocalizationSetLanguage(@"Spanish");
77+
//
78+
// If this function is not called it will use the default OS language.
79+
// If the language does not exists y returns the default OS language.
80+
- (void) setLanguage:(NSString*) l{
81+
#ifdef DEBUG
82+
NSLog(@"preferredLang: %@", l);
83+
#endif
84+
85+
NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
86+
87+
if ([l isEqualToString:@"en"]) {
88+
path = [[ NSBundle mainBundle ] pathForResource:@"Base" ofType:@"lproj" ];
89+
}
90+
if (path == nil) {
91+
//in case the language does not exists
92+
[self resetLocalization];
93+
}
94+
else {
95+
bundle = [NSBundle bundleWithPath:path];
96+
//
97+
[[NSUserDefaults standardUserDefaults] setObject:@[l] forKey:@"AppleLanguages"];
98+
//
99+
[[NSUserDefaults standardUserDefaults] synchronize];
100+
}
101+
}
102+
103+
// Just gets the current setted up language.
104+
// returns "es","fr",...
105+
//
106+
// example call:
107+
// NSString * currentL = LocalizationGetLanguage;
108+
- (NSString*) getLanguage{
109+
110+
NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
111+
112+
NSString *preferredLang = [languages objectAtIndex:0];
113+
114+
return preferredLang;
115+
}
116+
117+
// Resets the localization system, so it uses the OS default language.
118+
//
119+
// example call:
120+
// LocalizationReset;
121+
- (void) resetLocalization
122+
{
123+
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"];
124+
//
125+
[[NSUserDefaults standardUserDefaults] synchronize];
126+
//
127+
NSString *path = [[NSBundle mainBundle] pathForResource:@"Base" ofType:@"lproj" ];
128+
bundle = [NSBundle bundleWithPath:path];
129+
}
130+
131+
132+
@end

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
AMLocalizedString
2+
=================
3+
4+
####Copyright [AGGRESSIVE MEDIOCRITY](http://aggressive-mediocrity.blogspot.de/2010/03/custom-localization-system-for-your.html)

0 commit comments

Comments
 (0)