diff --git a/Tests/Tests/Lang/YLMomentTest+LangRu.m b/Tests/Tests/Lang/YLMomentTest+LangRu.m new file mode 100644 index 0000000..69806e1 --- /dev/null +++ b/Tests/Tests/Lang/YLMomentTest+LangRu.m @@ -0,0 +1,175 @@ +// +// YLMomentTest+LangRu.m +// YLMomentTests +// +// Created by Artem Korotkikh on 18.11.14. +// Copyright (c) 2014 YannickLoriot. All rights reserved. +// + + +#import + +#define EXP_SHORTHAND +#import "Expecta.h" + +#import "YLMoment.h" + +@interface YLMomentTest_LangRu : XCTestCase + +@end + + +@implementation YLMomentTest_LangRu + + +- (void)setUp +{ + [super setUp]; + [[YLMoment proxy] setLocale:[NSLocale localeWithLocaleIdentifier:@"ru_RU"]]; +} + +- (void)tearDown +{ + [[YLMoment proxy] setLocale:[NSLocale currentLocale]]; + + [super tearDown]; +} + +- (void)testLangFrom +{ + YLMoment *start = [YLMoment momentWithArray:@[@2007, @1, @28]]; + YLMoment *end; + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:44 forUnitKey:@"s"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"несколько секунд"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:45 forUnitKey:@"s"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"минуту"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:89 forUnitKey:@"s"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"минуту"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:90 forUnitKey:@"s"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"2 минуты"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:44 forUnitKey:@"m"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"44 минуты"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:45 forUnitKey:@"m"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"час"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:89 forUnitKey:@"m"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"час"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:90 forUnitKey:@"m"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"2 часа"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:9 forUnitKey:@"h"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"9 часов"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:21 forUnitKey:@"h"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"21 час"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:22 forUnitKey:@"h"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"день"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:35 forUnitKey:@"h"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"день"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:36 forUnitKey:@"h"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"2 дня"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:1 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"день"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:5 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"5 дней"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:25 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"25 дней"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:26 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"месяц"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:30 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"месяц"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:45 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"месяц"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:46 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"2 месяца"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:74 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"2 месяца"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:76 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"3 месяца"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:1 forUnitKey:@"M"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"месяц"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:5 forUnitKey:@"M"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"5 месяцев"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:344 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"11 месяцев"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:345 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"год"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:547 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"год"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:548 forUnitKey:@"d"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"2 года"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:1 forUnitKey:@"y"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"год"); + + end = [[YLMoment momentWithArray:@[@2007, @1, @28]] addAmountOfTime:5 forUnitKey:@"y"]; + expect([start fromMoment:end withSuffix:NO]).to.equal(@"5 лет"); +} + +- (void)testLangSuffix +{ + YLMoment *moment = [YLMoment now]; + YLMoment *future = [[YLMoment now] addAmountOfTime:3 forUnitKey:@"s"]; + YLMoment *past = [[YLMoment now] addAmountOfTime:-3 forUnitKey:@"s"]; + + expect([future fromMoment:moment]).to.equal(@"через несколько секунд"); + expect([past fromMoment:moment]).to.equal(@"несколько секунд назад"); +} + +- (void)testLangNowFromNow +{ + expect([[YLMoment now] fromNow]).to.equal(@"несколько секунд назад"); +} + +- (void)testLangFromNow +{ + YLMoment *reference1 = [[YLMoment now] addAmountOfTime:30 forCalendarUnit:NSCalendarUnitSecond]; + expect([reference1 fromNow]).to.equal(@"через несколько секунд"); + + YLMoment *reference2 = [[YLMoment now] addAmountOfTime:5 forCalendarUnit:NSCalendarUnitDay]; + expect([reference2 fromNow]).to.equal(@"через 5 дней"); + + YLMoment *reference3 = [[YLMoment now] addAmountOfTime:-1 forCalendarUnit:NSCalendarUnitDay]; + expect([reference3 fromNow]).to.equal(@"день назад"); +} + +- (void)testLangFromNowWithSuffix +{ + YLMoment *reference1 = [[YLMoment now] addAmountOfTime:-3 forCalendarUnit:NSCalendarUnitMonth]; + expect([reference1 fromNowWithSuffix:NO]).to.equal(@"3 месяца"); + + YLMoment *reference2 = [[YLMoment now] addAmountOfTime:9 forCalendarUnit:NSCalendarUnitHour]; + expect([reference2 fromNowWithSuffix:YES]).to.equal(@"через 9 часов"); +} + +- (void)testLandFromDate { + YLMoment *reference = [[YLMoment now] subtractAmountOfTime:6 forCalendarUnit:NSCalendarUnitMinute]; + expect([reference fromDate:[NSDate date]]).to.equal(@"6 минут назад"); +} + +@end diff --git a/Tests/YLMomentTests.xcodeproj/project.pbxproj b/Tests/YLMomentTests.xcodeproj/project.pbxproj index 14d9c9d..e8c3c59 100644 --- a/Tests/YLMomentTests.xcodeproj/project.pbxproj +++ b/Tests/YLMomentTests.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 276FAA0018D02B1A003A3E3F /* YLMomentTest+LangZh.m in Sources */ = {isa = PBXBuildFile; fileRef = 276FA9FE18D02B18003A3E3F /* YLMomentTest+LangZh.m */; }; A54704E318B0759600497886 /* YLMomentTest+LangPt.m in Sources */ = {isa = PBXBuildFile; fileRef = A54704E218B0759600497886 /* YLMomentTest+LangPt.m */; }; C3EC52F6F21D4DC5A1F10500 /* libPods-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC09F2AE9564D008900DA94 /* libPods-ios.a */; }; + D05C08F71A1B7E7500BEEDCA /* YLMomentTest+LangRu.m in Sources */ = {isa = PBXBuildFile; fileRef = D05C08F61A1B7E7500BEEDCA /* YLMomentTest+LangRu.m */; }; ED7DF6AE538742429A8AEA2C /* libPods-osx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AE61FE220675422EAEE6FB3F /* libPods-osx.a */; }; F425CFC61828296E002CABDC /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4605D41181C33E3007F83EF /* XCTest.framework */; }; F425CFCC1828296E002CABDC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F425CFCA1828296E002CABDC /* InfoPlist.strings */; }; @@ -54,13 +55,17 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 00D733B15202D0FF1E3FF7FC /* Pods-osx.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-osx.release.xcconfig"; path = "Pods/Target Support Files/Pods-osx/Pods-osx.release.xcconfig"; sourceTree = ""; }; 276FA9FE18D02B18003A3E3F /* YLMomentTest+LangZh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "YLMomentTest+LangZh.m"; sourceTree = ""; }; 2776776318D3FF9C00FB3B63 /* zh */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = zh; path = zh.lproj/YLMomentRelativeTimeLocalizable.strings; sourceTree = ""; }; - 2F21035625A34A29A4656C6A /* Pods-ios.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ios.xcconfig"; path = "Pods/Pods-ios.xcconfig"; sourceTree = ""; }; A54704E218B0759600497886 /* YLMomentTest+LangPt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "YLMomentTest+LangPt.m"; sourceTree = ""; }; ADC09F2AE9564D008900DA94 /* libPods-ios.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ios.a"; sourceTree = BUILT_PRODUCTS_DIR; }; AE61FE220675422EAEE6FB3F /* libPods-osx.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-osx.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - D38986F8261947CDA37C4DDE /* Pods-osx.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-osx.xcconfig"; path = "Pods/Pods-osx.xcconfig"; sourceTree = ""; }; + B2E16C5C760FDA24D6D2D5A4 /* Pods-ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ios.release.xcconfig"; path = "Pods/Target Support Files/Pods-ios/Pods-ios.release.xcconfig"; sourceTree = ""; }; + CCD07B0D6E309174B7BC35E6 /* Pods-osx.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-osx.debug.xcconfig"; path = "Pods/Target Support Files/Pods-osx/Pods-osx.debug.xcconfig"; sourceTree = ""; }; + D05C08F51A1B78C400BEEDCA /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/YLMomentRelativeTimeLocalizable.strings; sourceTree = ""; }; + D05C08F61A1B7E7500BEEDCA /* YLMomentTest+LangRu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "YLMomentTest+LangRu.m"; sourceTree = ""; }; + DB59440672FF2560896432FE /* Pods-ios.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ios.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ios/Pods-ios.debug.xcconfig"; sourceTree = ""; }; F425CFC018282516002CABDC /* iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; F425CFC51828296E002CABDC /* OSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; F425CFC91828296E002CABDC /* OSXTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "OSXTests-Info.plist"; sourceTree = ""; }; @@ -123,6 +128,17 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 942F860CBCA15E57623D161B /* Pods */ = { + isa = PBXGroup; + children = ( + DB59440672FF2560896432FE /* Pods-ios.debug.xcconfig */, + B2E16C5C760FDA24D6D2D5A4 /* Pods-ios.release.xcconfig */, + CCD07B0D6E309174B7BC35E6 /* Pods-osx.debug.xcconfig */, + 00D733B15202D0FF1E3FF7FC /* Pods-osx.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; F425CFC71828296E002CABDC /* OSXTests */ = { isa = PBXGroup; children = ( @@ -176,6 +192,7 @@ A54704E218B0759600497886 /* YLMomentTest+LangPt.m */, FA3A095418BDECE5001B2475 /* YLMomentTest+LangJa.m */, 276FA9FE18D02B18003A3E3F /* YLMomentTest+LangZh.m */, + D05C08F61A1B7E7500BEEDCA /* YLMomentTest+LangRu.m */, ); path = Lang; sourceTree = ""; @@ -208,8 +225,7 @@ F425CFC71828296E002CABDC /* OSXTests */, F4605D2E181C33AA007F83EF /* Frameworks */, F4DD860A18292B79008D0D88 /* Products */, - 2F21035625A34A29A4656C6A /* Pods-ios.xcconfig */, - D38986F8261947CDA37C4DDE /* Pods-osx.xcconfig */, + 942F860CBCA15E57623D161B /* Pods */, ); sourceTree = ""; }; @@ -331,6 +347,7 @@ pt, ja, zh, + ru, ); mainGroup = F4605D09181C326A007F83EF; productRefGroup = F4605D09181C326A007F83EF; @@ -377,7 +394,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-osx-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-osx/Pods-osx-resources.sh\"\n"; showEnvVarsInLog = 0; }; 720CE271DFCB4ED1B5066E61 /* Check Pods Manifest.lock */ = { @@ -406,7 +423,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-ios-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ios/Pods-ios-resources.sh\"\n"; showEnvVarsInLog = 0; }; C046DAF74BAA4A0E9999F383 /* Check Pods Manifest.lock */ = { @@ -462,6 +479,7 @@ F425CFEA182844D1002CABDC /* YLMomentTest+LangFr.m in Sources */, F425CFE8182844D1002CABDC /* YLMomentTest+LangEn.m in Sources */, F425CFE6182844D1002CABDC /* YLMomentTests+Helpers.m in Sources */, + D05C08F71A1B7E7500BEEDCA /* YLMomentTest+LangRu.m in Sources */, F425CFE4182844D1002CABDC /* YLMomentTests+Format.m in Sources */, F4381B281886B744008C50E0 /* YLMomentTest+LangDe.m in Sources */, A54704E318B0759600497886 /* YLMomentTest+LangPt.m in Sources */, @@ -498,6 +516,7 @@ F43B57FC18B22E41001E9993 /* sq */, FA0470E918BDEEEA00BC1B91 /* ja */, 2776776318D3FF9C00FB3B63 /* zh */, + D05C08F51A1B78C400BEEDCA /* ru */, ); name = YLMomentRelativeTimeLocalizable.strings; sourceTree = ""; @@ -515,7 +534,7 @@ /* Begin XCBuildConfiguration section */ F425CFD31828296E002CABDC /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = D38986F8261947CDA37C4DDE /* Pods-osx.xcconfig */; + baseConfigurationReference = CCD07B0D6E309174B7BC35E6 /* Pods-osx.debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -565,7 +584,7 @@ }; F425CFD41828296E002CABDC /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = D38986F8261947CDA37C4DDE /* Pods-osx.xcconfig */; + baseConfigurationReference = 00D733B15202D0FF1E3FF7FC /* Pods-osx.release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -632,7 +651,7 @@ }; F4605D3F181C33AA007F83EF /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 2F21035625A34A29A4656C6A /* Pods-ios.xcconfig */; + baseConfigurationReference = DB59440672FF2560896432FE /* Pods-ios.debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -683,7 +702,7 @@ }; F4605D40181C33AA007F83EF /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 2F21035625A34A29A4656C6A /* Pods-ios.xcconfig */; + baseConfigurationReference = B2E16C5C760FDA24D6D2D5A4 /* Pods-ios.release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; diff --git a/YLMoment/Localization/ru.lproj/YLMomentRelativeTimeLocalizable.strings b/YLMoment/Localization/ru.lproj/YLMomentRelativeTimeLocalizable.strings new file mode 100644 index 0000000..a91de28 --- /dev/null +++ b/YLMoment/Localization/ru.lproj/YLMomentRelativeTimeLocalizable.strings @@ -0,0 +1,36 @@ +/* + YLMomentFormat.strings + YLMoment + + Created by Artem Korotkikh on 18/11/2014. + Translation comes from the moment.js project. Learn more at http://momentjs.com +*/ + +"future" = "через %@"; +"past" = "%@ назад"; +"s" = "несколько секунд"; +"1m" = "минуту"; +"1h" = "час"; +"1d" = "день"; +"1M" = "месяц"; +"1y" = "год"; + +"m" = "%d минута"; +"mm" = "%d минуты"; +"mmm" = "%d минут"; + +"h" = "%d час"; +"hh" = "%d часа"; +"hhh" = "%d часов"; + +"d" = "%d день"; +"dd" = "%d дня"; +"ddd" = "%d дней"; + +"M" = "%d месяц"; +"MM" = "%d месяца"; +"MMM" = "%d месяцев"; + +"y" = "%d год"; +"yy" = "%d года"; +"yyy" = "%d лет"; diff --git a/YLMoment/YLMoment.m b/YLMoment/YLMoment.m index 7f56644..53d05d4 100644 --- a/YLMoment/YLMoment.m +++ b/YLMoment/YLMoment.m @@ -295,7 +295,8 @@ - (NSString *)fromDate:(NSDate *)date withSuffix:(BOOL)suffixed { // Get the lang bundle NSBundle *langBundle = _langBundle ?: [[[self class] proxy] langBundle] ?: [NSBundle mainBundle]; - + NSString * language = [[[YLMoment proxy] locale] localeIdentifier]; + // Compute the time interval double referenceTime = [_date timeIntervalSinceDate:date]; double seconds = round(fabs(referenceTime)); @@ -307,47 +308,103 @@ - (NSString *)fromDate:(NSDate *)date withSuffix:(BOOL)suffixed // Build the formatted string NSString *formattedString = @""; int unit = 0; - if (seconds < 45) - { - formattedString = [langBundle localizedStringForKey:@"s" value:@"a few seconds" table:kYLMomentRelativeTimeStringTable]; - unit = seconds; - } else if (minutes == 1) - { - formattedString = [langBundle localizedStringForKey:@"m" value:@"a minute" table:kYLMomentRelativeTimeStringTable]; - } else if (minutes < 45) - { - formattedString = [langBundle localizedStringForKey:@"mm" value:@"%d minutes" table:kYLMomentRelativeTimeStringTable]; - unit = minutes; - } else if (hours == 1) - { - formattedString = [langBundle localizedStringForKey:@"h" value:@"an hour" table:kYLMomentRelativeTimeStringTable]; - } else if (hours < 22) - { - formattedString = [langBundle localizedStringForKey:@"hh" value:@"%d hours" table:kYLMomentRelativeTimeStringTable]; - unit = hours; - } else if (days == 1) - { - formattedString = [langBundle localizedStringForKey:@"d" value:@"a day" table:kYLMomentRelativeTimeStringTable]; - } else if (days <= 25) - { - formattedString = [langBundle localizedStringForKey:@"dd" value:@"%d days" table:kYLMomentRelativeTimeStringTable]; - unit = days; - } else if (days <= 45) - { - formattedString = [langBundle localizedStringForKey:@"M" value:@"a month" table:kYLMomentRelativeTimeStringTable]; - } else if (days < 345) - { - formattedString = [langBundle localizedStringForKey:@"MM" value:@"%d months" table:kYLMomentRelativeTimeStringTable]; - unit = round(days / 30); - } else if (years == 1) + + if([language isEqualToString:@"ru_RU"] || [language isEqualToString:@"ru"]) { - formattedString = [langBundle localizedStringForKey:@"y" value:@"a year" table:kYLMomentRelativeTimeStringTable]; - } else + NSArray * minuteStrings = @[@"m", @"mm", @"mmm"]; + NSArray * hourStrings = @[@"h", @"hh", @"hhh"]; + NSArray * dayStrings = @[@"d", @"dd", @"ddd"]; + NSArray * monthStrings = @[@"M", @"MM", @"MMM"]; + NSArray * yearStrings = @[@"y", @"yy", @"yyy"]; + + if (seconds < 45) + { + formattedString = [langBundle localizedStringForKey:@"s" value:@"несколько секунд" table:kYLMomentRelativeTimeStringTable]; + unit = seconds; + } else if (minutes == 1) + { + formattedString = [langBundle localizedStringForKey:@"1m" value:@"минуту" table:kYLMomentRelativeTimeStringTable]; + } else if (minutes < 45) + { + formattedString = [langBundle localizedStringForKey:[self wordFromArray:minuteStrings forNumber:minutes] value:@"%d minutes" table:kYLMomentRelativeTimeStringTable]; + unit = minutes; + } else if (hours == 1) + { + formattedString = [langBundle localizedStringForKey:@"1h" value:@"an hour" table:kYLMomentRelativeTimeStringTable]; + } else if (hours < 22) + { + formattedString = [langBundle localizedStringForKey:[self wordFromArray:hourStrings forNumber:hours] value:@"%d hours" table:kYLMomentRelativeTimeStringTable]; + unit = hours; + } else if (days == 1) + { + formattedString = [langBundle localizedStringForKey:@"1d" value:@"a day" table:kYLMomentRelativeTimeStringTable]; + } else if (days <= 25) + { + formattedString = [langBundle localizedStringForKey:[self wordFromArray:dayStrings forNumber:days] value:@"%d days" table:kYLMomentRelativeTimeStringTable]; + unit = days; + } else if (days <= 45) + { + formattedString = [langBundle localizedStringForKey:@"1M" value:@"a month" table:kYLMomentRelativeTimeStringTable]; + } else if (days < 345) + { + int months = round(days / 30); + formattedString = [langBundle localizedStringForKey:[self wordFromArray:monthStrings forNumber:months] value:@"%d months" table:kYLMomentRelativeTimeStringTable]; + unit = months; + } else if (years == 1) + { + formattedString = [langBundle localizedStringForKey:@"1y" value:@"a year" table:kYLMomentRelativeTimeStringTable]; + } else + { + formattedString = [langBundle localizedStringForKey:[self wordFromArray:yearStrings forNumber:years] value:@"%d years" table:kYLMomentRelativeTimeStringTable]; + unit = years; + } + formattedString = [NSString stringWithFormat:formattedString, unit]; + } + else { - formattedString = [langBundle localizedStringForKey:@"yy" value:@"%d years" table:kYLMomentRelativeTimeStringTable]; - unit = years; + + if (seconds < 45) + { + formattedString = [langBundle localizedStringForKey:@"s" value:@"a few seconds" table:kYLMomentRelativeTimeStringTable]; + unit = seconds; + } else if (minutes == 1) + { + formattedString = [langBundle localizedStringForKey:@"m" value:@"a minute" table:kYLMomentRelativeTimeStringTable]; + } else if (minutes < 45) + { + formattedString = [langBundle localizedStringForKey:@"mm" value:@"%d minutes" table:kYLMomentRelativeTimeStringTable]; + unit = minutes; + } else if (hours == 1) + { + formattedString = [langBundle localizedStringForKey:@"h" value:@"an hour" table:kYLMomentRelativeTimeStringTable]; + } else if (hours < 22) + { + formattedString = [langBundle localizedStringForKey:@"hh" value:@"%d hours" table:kYLMomentRelativeTimeStringTable]; + unit = hours; + } else if (days == 1) + { + formattedString = [langBundle localizedStringForKey:@"d" value:@"a day" table:kYLMomentRelativeTimeStringTable]; + } else if (days <= 25) + { + formattedString = [langBundle localizedStringForKey:@"dd" value:@"%d days" table:kYLMomentRelativeTimeStringTable]; + unit = days; + } else if (days <= 45) + { + formattedString = [langBundle localizedStringForKey:@"M" value:@"a month" table:kYLMomentRelativeTimeStringTable]; + } else if (days < 345) + { + formattedString = [langBundle localizedStringForKey:@"MM" value:@"%d months" table:kYLMomentRelativeTimeStringTable]; + unit = round(days / 30); + } else if (years == 1) + { + formattedString = [langBundle localizedStringForKey:@"y" value:@"a year" table:kYLMomentRelativeTimeStringTable]; + } else + { + formattedString = [langBundle localizedStringForKey:@"yy" value:@"%d years" table:kYLMomentRelativeTimeStringTable]; + unit = years; + } + formattedString = [NSString stringWithFormat:formattedString, unit]; } - formattedString = [NSString stringWithFormat:formattedString, unit]; // If the string needs to be suffixed if (suffixed) @@ -656,6 +713,21 @@ + (NSCalendarUnit)calendarUnitForKey:(NSString *)key return -1; } +/// Return rigth word form from array of words next to the numeral +/// Exampe for getting «1 минута» +/// array ['минута', 'минуты', 'минут'], num = 1 +-(NSString *) wordFromArray:(NSArray *)words forNumber:(int)num +{ + int n = num%100; + int n1 = n%10; + if (n > 10 && n < 20) return words[2]; + if (n1 > 1 && n1 < 5) return words[1]; + if (n1 == 1) return words[0]; + + return words[2]; +} + + #pragma mark - Private Methods - (id)initProxy