Skip to content

Commit

Permalink
Merge pull request #1 from bradyholt/locales
Browse files Browse the repository at this point in the history
Implement i18n
  • Loading branch information
bradymholt authored Jul 29, 2016
2 parents f1259f7 + 2a92c9e commit 9c6f004
Show file tree
Hide file tree
Showing 65 changed files with 6,382 additions and 423 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ This library was ported from the original C# implemenation called [cron-expressi
- Zero dependencies
- Supports all cron expression special characters including * / , - ? L W, #
- Supports 5, 6 (w/ seconds or year), or 7 (w/ seconds and year) part cron expressions
- (i18n support with 14 languages coming soon)

- i18n support with 14 languages

## Installation
cRonstrue is exported as an [UMD](https://github.com/umdjs/umd) module so it will work in an [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD), [CommonJS](http://wiki.commonjs.org/wiki/CommonJS) or browser global context.
Expand All @@ -22,8 +21,11 @@ var cronstrue = require('cronstrue');
The `cronstrue.min.js` file from the `/dist` folder in the npm package should be served to the browser. There are no dependencies so you can simply include the library in a `<script>` tag.
```
<script src="cronstrue.min.js" type="text/javascript"></script>
var cronstrue = window.cronstrue;
<script>
var cronstrue = window.cronstrue;
</script>
```

## Usage

```
Expand All @@ -39,6 +41,41 @@ cronstrue.toString("23 12 * * SUN#2");

For more usage examples, including a demonstration of how cRonstrue can handle some very complex cron expressions, you can [reference the unit tests](https://github.com/bradyholt/cronstrue/blob/master/test/cronstrue.js).

## i18n

To use the i18n support cRonstrue provides, you must use the packaged library that contains the locale transalations. Once you do this, you can pass the name of a supported locale as an option to `cronstrue.toString()`. For example, for the es (Spanish) locale, you would use: `cronstrue.toString("* * * * *", { locale: "es" });`.

### Node
```
var cronstrue = require('cronstrue/i18n');
cronstrue.toString("*/5 * * * *", { locale: "fr" });
```
### Browser
The `cronstrue-i18n.min.js` file from the `/dist` folder in the npm package should be served to the browser.
```
<script src="cronstrue-i18n.min.js" type="text/javascript"></script>
<script>
cronstrue.toString("*/5 * * * *", { locale: "fr" });
</script>
```

### Supported Locales

- en - English
- nl - Dutch
- fr - French
- de - German
- it - Italian
- nb - Norwegian
- pl - Polish
- pt_BR - Portuguese (Brazil)
- ro - Romanian
- ru - Russian
- es - Spanish
- tr - Turkish
- uk - Ukrainian
- zh_CN - Chinese (Simplified)

## License

cRonstrue is freely distributable under the terms of the [MIT license](https://github.com/bradyholt/cronstrue/blob/master/LICENSE).
2,882 changes: 2,882 additions & 0 deletions dist/cronstrue-i18n.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/cronstrue-i18n.min.js

Large diffs are not rendered by default.

330 changes: 217 additions & 113 deletions dist/cronstrue.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cronstrue.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/declarations/cronstrue-en.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { Cronstrue } from "./cronstrue";
export = Cronstrue;
2 changes: 2 additions & 0 deletions dist/declarations/cronstrue-i18n.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { Cronstrue } from "./cronstrue";
export = Cronstrue;
11 changes: 6 additions & 5 deletions dist/declarations/cronstrue.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Options } from './options';
import { Locale } from './locale/locale';
declare class cronstrue {
import { Options } from "./options";
import { Locale } from "./i18n/locale";
import { LocaleLoader } from "./i18n/localeLoader";
export declare class Cronstrue {
static locales: {
[name: string]: Locale;
};
Expand All @@ -10,7 +11,8 @@ declare class cronstrue {
options: Options;
i18n: Locale;
static toString(expression: string, {throwExceptionOnParseError, verbose, dayOfWeekStartIndexZero, use24HourTimeFormat, locale}?: Options): string;
static initialize(): void;
static initialize(localesLoader: LocaleLoader): void;
static locale(localeName: string): void;
constructor(expression: string, options: Options);
protected getFullDescription(): string;
protected getTimeOfDayDescription(): string;
Expand All @@ -26,4 +28,3 @@ declare class cronstrue {
protected formatTime(hourExpression: string, minuteExpression: string, secondExpression: string): string;
protected transformVerbosity(description: string, useVerboseFormat: boolean): string;
}
export = cronstrue;
6 changes: 6 additions & 0 deletions dist/declarations/i18n/LocaleLoader.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Locale } from "./locale";
export interface LocaleLoader {
load(availableLocales: {
[name: string]: Locale;
}): void;
}
14 changes: 14 additions & 0 deletions dist/declarations/i18n/allLocales.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export { en } from "./locales/en";
export { de } from "./locales/de";
export { es } from "./locales/es";
export { fr } from "./locales/fr";
export { it } from "./locales/it";
export { nl } from "./locales/nl";
export { nb } from "./locales/nb";
export { pl } from "./locales/pl";
export { pt_BR } from "./locales/pt_BR";
export { ro } from "./locales/ro";
export { ru } from "./locales/ru";
export { tr } from "./locales/tr";
export { uk } from "./locales/uk";
export { zh_CN } from "./locales/zh_CN";
6 changes: 6 additions & 0 deletions dist/declarations/i18n/allLocalesLoader.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Locale } from "./locale";
export declare class allLocalesLoader {
load(availableLocales: {
[name: string]: Locale;
}): void;
}
6 changes: 6 additions & 0 deletions dist/declarations/i18n/enLocaleLoader.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Locale } from "./locale";
export declare class enLocaleLoader {
load(availableLocales: {
[name: string]: Locale;
}): void;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface Locale {
Use24HourTimeFormatByDefault(): boolean;
AnErrorOccuredWhenGeneratingTheExpressionD(): string;
EveryMinute(): string;
EveryHour(): string;
Expand Down Expand Up @@ -47,4 +48,6 @@ export interface Locale {
ComaEveryHour(): string;
ComaEveryX0Years(): string;
CommaStartingX0(): string;
DaysOfTheWeek(): string[];
MonthsOfTheYear(): string[];
}
54 changes: 54 additions & 0 deletions dist/declarations/i18n/locales/de.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Locale } from "../locale";
export declare class de implements Locale {
AtX0SecondsPastTheMinuteGt20(): string;
AtX0MinutesPastTheHourGt20(): string;
ComaMonthX0ThroughMonthX1(): string;
ComaYearX0ThroughYearX1(): string;
Use24HourTimeFormatByDefault(): boolean;
EveryMinute(): string;
EveryHour(): string;
AnErrorOccuredWhenGeneratingTheExpressionD(): string;
AtSpace(): string;
EveryMinuteBetweenX0AndX1(): string;
At(): string;
SpaceAnd(): string;
EverySecond(): string;
EveryX0Seconds(): string;
SecondsX0ThroughX1PastTheMinute(): string;
AtX0SecondsPastTheMinute(): string;
EveryX0Minutes(): string;
MinutesX0ThroughX1PastTheHour(): string;
AtX0MinutesPastTheHour(): string;
EveryX0Hours(): string;
BetweenX0AndX1(): string;
AtX0(): string;
ComaEveryDay(): string;
ComaEveryX0DaysOfTheWeek(): string;
ComaX0ThroughX1(): string;
First(): string;
Second(): string;
Third(): string;
Forth(): string;
Fifth(): string;
ComaOnThe(): string;
SpaceX0OfTheMonth(): string;
ComaOnTheLastX0OfTheMonth(): string;
ComaOnlyOnX0(): string;
ComaEveryX0Months(): string;
ComaOnlyInX0(): string;
ComaOnTheLastDayOfTheMonth(): string;
ComaOnTheLastWeekdayOfTheMonth(): string;
FirstWeekday(): string;
WeekdayNearestDayX0(): string;
ComaOnTheX0OfTheMonth(): string;
ComaEveryX0Days(): string;
ComaBetweenDayX0AndX1OfTheMonth(): string;
ComaOnDayX0OfTheMonth(): string;
SpaceAndSpace(): string;
ComaEveryMinute(): string;
ComaEveryHour(): string;
ComaEveryX0Years(): string;
CommaStartingX0(): string;
DaysOfTheWeek(): string[];
MonthsOfTheYear(): string[];
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Locale } from './locale';
import { Locale } from "../locale";
export declare class en implements Locale {
AtX0SecondsPastTheMinuteGt20(): string;
AtX0MinutesPastTheHourGt20(): string;
ComaMonthX0ThroughMonthX1(): string;
ComaYearX0ThroughYearX1(): string;
Use24HourTimeFormatByDefault(): boolean;
AnErrorOccuredWhenGeneratingTheExpressionD(): string;
EveryMinute(): string;
EveryHour(): string;
Expand All @@ -11,19 +16,15 @@ export declare class en implements Locale {
EveryX0Seconds(): string;
SecondsX0ThroughX1PastTheMinute(): string;
AtX0SecondsPastTheMinute(): string;
AtX0SecondsPastTheMinuteGt20(): string;
EveryX0Minutes(): string;
MinutesX0ThroughX1PastTheHour(): string;
AtX0MinutesPastTheHour(): string;
AtX0MinutesPastTheHourGt20(): string;
EveryX0Hours(): string;
BetweenX0AndX1(): string;
AtX0(): string;
ComaEveryDay(): string;
ComaEveryX0DaysOfTheWeek(): string;
ComaX0ThroughX1(): string;
ComaMonthX0ThroughMonthX1(): string;
ComaYearX0ThroughYearX1(): string;
First(): string;
Second(): string;
Third(): string;
Expand All @@ -48,4 +49,6 @@ export declare class en implements Locale {
ComaEveryHour(): string;
ComaEveryX0Years(): string;
CommaStartingX0(): string;
DaysOfTheWeek(): string[];
MonthsOfTheYear(): string[];
}
54 changes: 54 additions & 0 deletions dist/declarations/i18n/locales/es.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Locale } from "../locale";
export declare class es implements Locale {
AtX0SecondsPastTheMinuteGt20(): string;
AtX0MinutesPastTheHourGt20(): string;
ComaMonthX0ThroughMonthX1(): string;
ComaYearX0ThroughYearX1(): string;
Use24HourTimeFormatByDefault(): boolean;
AnErrorOccuredWhenGeneratingTheExpressionD(): string;
At(): string;
AtSpace(): string;
AtX0(): string;
AtX0MinutesPastTheHour(): string;
AtX0SecondsPastTheMinute(): string;
BetweenX0AndX1(): string;
ComaBetweenDayX0AndX1OfTheMonth(): string;
ComaEveryDay(): string;
ComaEveryHour(): string;
ComaEveryMinute(): string;
ComaEveryX0Days(): string;
ComaEveryX0DaysOfTheWeek(): string;
ComaEveryX0Months(): string;
ComaOnDayX0OfTheMonth(): string;
ComaOnlyInX0(): string;
ComaOnlyOnX0(): string;
ComaOnThe(): string;
ComaOnTheLastDayOfTheMonth(): string;
ComaOnTheLastWeekdayOfTheMonth(): string;
ComaOnTheLastX0OfTheMonth(): string;
ComaOnTheX0OfTheMonth(): string;
ComaX0ThroughX1(): string;
EveryHour(): string;
EveryMinute(): string;
EveryMinuteBetweenX0AndX1(): string;
EverySecond(): string;
EveryX0Hours(): string;
EveryX0Minutes(): string;
EveryX0Seconds(): string;
Fifth(): string;
First(): string;
FirstWeekday(): string;
Forth(): string;
MinutesX0ThroughX1PastTheHour(): string;
Second(): string;
SecondsX0ThroughX1PastTheMinute(): string;
SpaceAnd(): string;
SpaceAndSpace(): string;
SpaceX0OfTheMonth(): string;
Third(): string;
WeekdayNearestDayX0(): string;
ComaEveryX0Years(): string;
CommaStartingX0(): string;
DaysOfTheWeek(): string[];
MonthsOfTheYear(): string[];
}
56 changes: 56 additions & 0 deletions dist/declarations/i18n/locales/fr.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Locale } from "../locale";
export declare class fr implements Locale {
AtX0SecondsPastTheMinuteGt20(): string;
AtX0MinutesPastTheHourGt20(): string;
ComaMonthX0ThroughMonthX1(): string;
ComaYearX0ThroughYearX1(): string;
Use24HourTimeFormatByDefault(): boolean;
EveryMinute(): string;
EveryHour(): string;
AnErrorOccuredWhenGeneratingTheExpressionD(): string;
AtSpace(): string;
EveryMinuteBetweenX0AndX1(): string;
At(): string;
SpaceAnd(): string;
EverySecond(): string;
EveryX0Seconds(): string;
SecondsX0ThroughX1PastTheMinute(): string;
AtX0SecondsPastTheMinute(): string;
EveryX0Minutes(): string;
MinutesX0ThroughX1PastTheHour(): string;
AtX0MinutesPastTheHour(): string;
EveryX0Hours(): string;
BetweenX0AndX1(): string;
AtX0(): string;
ComaEveryDay(): string;
ComaEveryX0DaysOfTheWeek(): string;
ComaX0ThroughX1(): string;
First(): string;
Second(): string;
Third(): string;
Forth(): string;
Fifth(): string;
ComaOnThe(): string;
SpaceX0OfTheMonth(): string;
ComaOnTheLastX0OfTheMonth(): string;
ComaOnlyOnX0(): string;
ComaEveryX0Months(): string;
ComaOnlyInX0(): string;
ComaOnTheLastDayOfTheMonth(): string;
ComaOnTheLastWeekdayOfTheMonth(): string;
FirstWeekday(): string;
WeekdayNearestDayX0(): string;
ComaOnTheX0OfTheMonth(): string;
ComaEveryX0Days(): string;
ComaBetweenDayX0AndX1OfTheMonth(): string;
ComaOnDayX0OfTheMonth(): string;
SpaceAndSpace(): string;
ComaEveryMinute(): string;
ComaEveryHour(): string;
ComaEveryX0Years(): string;
ComaDaysX0ThroughX1(): string;
WeekSpaceAndSpace(): string;
CommaStartingX0(): string;
DaysOfTheWeek(): string[];
MonthsOfTheYear(): string[];
}
Loading

0 comments on commit 9c6f004

Please sign in to comment.