Skip to content

Commit

Permalink
feat(i18n): add translation for timestamps and dates #33
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesjo committed Jul 17, 2019
1 parent 5432427 commit 6b80062
Show file tree
Hide file tree
Showing 26 changed files with 43 additions and 30 deletions.
2 changes: 1 addition & 1 deletion electron/indicator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ipcMain, Menu, systemPreferences, Tray } from 'electron';
import { existsSync, readFileSync } from 'fs';
// const dbus = require('./dbus');
import * as moment from 'moment-mini';
import * as moment from 'moment';
import { errorHandler } from './error-handler';
import { IPC_CURRENT_TASK_UPDATED, IPC_POMODORO_UPDATE } from './ipc-events.const';

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"electron-log": "^3.0.1",
"googleapis": "^40.0.0",
"jira-client-fork": "^4.2.1",
"moment-mini": "^2.22.1"
"moment": "^2.24.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.800.2",
Expand Down
12 changes: 12 additions & 0 deletions src/app/app.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ export enum LanguageCode {
zh = 'zh',
}

export enum LanguageCodeMomentMap {
en = 'en',
es = 'es',
de = 'de',
ar = 'ar',
fr = 'fr',
ja = 'ja',
ru = 'ru',
tr = 'tr',
zh = 'zh-cn',
}

// we're assuming that the other language speakers are likely to speak english
// and as english offers most likely the best experience, we use it as default
export const AUTO_SWITCH_LNGS: LanguageCode[] = [
Expand Down
5 changes: 4 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {ProcrastinationModule} from './features/procrastination/procrastination.
import {TaskRepeatCfgModule} from './features/task-repeat-cfg/task-repeat-cfg.module';
import {TranslateLoader, TranslateModule, TranslateService} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import {AUTO_SWITCH_LNGS, LanguageCode} from './app.constants';
import {AUTO_SWITCH_LNGS, LanguageCode, LanguageCodeMomentMap} from './app.constants';
import * as moment from 'moment';

// NOTE: export required for aot to work
export function createTranslateLoader(http: HttpClient) {
Expand Down Expand Up @@ -101,9 +102,11 @@ export class AppModule {
) {
const lng = this._translateService.getBrowserLang() as LanguageCode;
this._translateService.setDefaultLang('en');
moment.locale('en');

if (AUTO_SWITCH_LNGS.includes(lng)) {
this._translateService.use(lng);
moment.locale(LanguageCodeMomentMap[lng]);
}
}
}
5 changes: 4 additions & 1 deletion src/app/features/config/store/global-config.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import {SnackOpen} from '../../../core/snack/store/snack.actions';
import {ElectronService} from 'ngx-electron';
import {KeyboardConfig} from '../global-config.model';
import {IPC_REGISTER_GLOBAL_SHORTCUTS_EVENT} from '../../../../../electron/ipc-events.const';
import {IS_ELECTRON} from '../../../app.constants';
import {IS_ELECTRON, LanguageCodeMomentMap} from '../../../app.constants';
import {TranslateService} from '@ngx-translate/core';
import {T} from '../../../t.const';
import * as moment from 'moment';

@Injectable()
export class GlobalConfigEffects {
Expand Down Expand Up @@ -76,6 +77,7 @@ export class GlobalConfigEffects {
tap((action: UpdateGlobalConfigSection) => {
const lng = action.payload.sectionCfg['lng'];
this._translateService.use(lng);
moment.locale(LanguageCodeMomentMap[lng]);
})
);

Expand All @@ -88,6 +90,7 @@ export class GlobalConfigEffects {
tap((action: LoadGlobalConfig) => {
const lng = action.payload.cfg.lang.lng;
this._translateService.use(lng);
moment.locale(LanguageCodeMomentMap[lng]);
})
);

Expand Down
2 changes: 1 addition & 1 deletion src/app/features/google/google-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Injectable} from '@angular/core';
import {GOOGLE_DEFAULT_FIELDS_FOR_DRIVE, GOOGLE_DISCOVERY_DOCS, GOOGLE_SCOPES, GOOGLE_SETTINGS} from './google.const';
import * as moment from 'moment-mini';
import * as moment from 'moment';
import {IS_ELECTRON} from '../../app.constants';
import {MultiPartBuilder} from './util/multi-part-builder';
import {HttpClient, HttpHeaders, HttpParams, HttpRequest} from '@angular/common/http';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {ProjectService} from '../../project/project.service';
import {TaskService} from '../../tasks/task.service';
import {SnackService} from '../../../core/snack/snack.service';
import {takeUntil} from 'rxjs/operators';
import * as moment from 'moment-mini';
import * as moment from 'moment';
import {expandAnimation} from '../../../ui/animations/expand.ani';
import 'moment-duration-format';
import {msToClockString} from '../../../ui/duration/ms-to-clock-string.pipe';
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/google/store/google-drive-sync.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {SyncService} from '../../../imex/sync/sync.service';
import {SnackOpen} from '../../../core/snack/store/snack.actions';
import {DEFAULT_SYNC_FILE_NAME} from '../google.const';
import {DialogConfirmDriveSyncSaveComponent} from '../dialog-confirm-drive-sync-save/dialog-confirm-drive-sync-save.component';
import * as moment from 'moment-mini';
import * as moment from 'moment';
import {DialogConfirmDriveSyncLoadComponent} from '../dialog-confirm-drive-sync-load/dialog-confirm-drive-sync-load.component';
import {AppDataComplete} from '../../../imex/sync/sync.model';
import {selectIsGoogleDriveSaveInProgress} from './google-drive-sync.reducer';
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/issue/jira/jira-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {SearchResultItem} from '../issue';
import {fromPromise} from 'rxjs/internal-compatibility';
import {catchError, first} from 'rxjs/operators';
import {JiraIssue} from './jira-issue/jira-issue.model';
import * as moment from 'moment-mini';
import * as moment from 'moment';
import {getJiraResponseErrorTxt} from '../../../util/get-jira-response-error-text';
import {BannerService} from '../../../core/banner/banner.service';
import {BannerId} from '../../../core/banner/banner.model';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {SIMPLE_SUMMARY_DEFAULTS} from '../../project/project.const';
import Clipboard from 'clipboard';
import {SnackService} from '../../../core/snack/snack.service';
import {getWorklogStr} from '../../../util/get-work-log-str';
import * as moment from 'moment-mini';
import * as moment from 'moment';
import 'moment-duration-format';
import {roundDuration} from '../../../util/round-duration';

Expand Down
2 changes: 1 addition & 1 deletion src/app/features/tasks/util/get-today-str.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {WORKLOG_DATE_STR_FORMAT} from '../../../app.constants';
import * as moment from 'moment-mini';
import * as moment from 'moment';
// TODO maybe remove in favor of getWorklogStr
export const getTodayStr = () => moment().format(WORKLOG_DATE_STR_FORMAT);
2 changes: 1 addition & 1 deletion src/app/features/worklog/map-archive-to-worklog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {EntityState} from '@ngrx/entity';
import {Task} from '../tasks/task.model';
import {getWeeksInMonth} from '../../util/get-weeks-in-month';
import {getWeekNumber} from '../../util/get-week-number';
import * as moment from 'moment-mini';
import * as moment from 'moment';
import {WorkStartEnd} from '../project/project.model';
import {Worklog, WorklogDay, WorklogMonth, WorklogWeek, WorklogYear} from './worklog.model';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Subscription} from 'rxjs';
import {WorkStartEnd} from '../../project/project.model';
import {WORKLOG_EXPORT_DEFAULTS} from '../../project/project.const';
import {getWorklogStr} from '../../../util/get-work-log-str';
import * as moment from 'moment-mini';
import * as moment from 'moment';
import 'moment-duration-format';
import {unique} from '../../../util/unique';
import {msToString} from '../../../ui/duration/ms-to-string.pipe';
Expand Down
2 changes: 1 addition & 1 deletion src/app/imex/migrate/migrate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {DEFAULT_JIRA_CFG} from '../../features/issue/jira/jira.const';
import {initialTaskState} from '../../features/tasks/store/task.reducer';
import {EntityState} from '@ngrx/entity';
import {DEFAULT_TASK, Task} from '../../features/tasks/task.model';
import * as moment from 'moment-mini';
import * as moment from 'moment';
import {JiraIssue} from '../../features/issue/jira/jira-issue/jira-issue.model';
import {GithubIssue} from '../../features/issue/github/github-issue/github-issue.model';
import {IssueProviderKey} from '../../features/issue/issue';
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/daily-summary/daily-summary.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {filter, map, shareReplay, startWith, switchMap, take} from 'rxjs/operato
import {GoogleApiService} from '../../features/google/google-api.service';
import {ProjectService} from '../../features/project/project.service';
import {getWorklogStr} from '../../util/get-work-log-str';
import * as moment from 'moment-mini';
import * as moment from 'moment';
import {RoundTimeOption} from '../../features/project/project.model';
import {T} from '../../t.const';

Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/duration/duration-from-string.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment-mini';
import * as moment from 'moment';


@Pipe({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ViewChild
} from '@angular/core';
import shortid from 'shortid';
import * as moment from 'moment-mini';
import * as moment from 'moment';
import {dotAnimation} from './dot.ani';

@Component({
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/duration/ms-to-clock-string.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment-mini';
import * as moment from 'moment';

export const msToClockString = (value: any, showSeconds?: boolean, isHideEmptyPlaceholder?: boolean): string => {
const md = moment.duration(value);
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/duration/ms-to-minute-clock-string.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment-mini';
import * as moment from 'moment';

export const msToMinuteClockString = (value: any): string => {
const md = moment.duration(value);
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/duration/ms-to-string.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment-mini';
import * as moment from 'moment';

export const msToString = (value: any, showSeconds?: boolean, isHideEmptyPlaceholder?: boolean): string => {
const md = moment.duration(value);
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/pipes/humanize-timestamp.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment-mini';
import * as moment from 'moment';


@Pipe({
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/pipes/moment-format.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment-mini';
import * as moment from 'moment';

@Pipe({
name: 'momentFormat'
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/get-date-range-for-week.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// NOTE: cuts off at month start and end per default
import * as moment from 'moment-mini';
import * as moment from 'moment';

export const getDateRangeForWeek = (year: number, weekNr: number, month?: number): {
rangeStart: Date,
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/get-work-log-str.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as moment from 'moment-mini';
import * as moment from 'moment';

import {WORKLOG_DATE_STR_FORMAT} from '../app.constants';

Expand Down
2 changes: 1 addition & 1 deletion src/app/util/round-duration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as moment from 'moment-mini';
import * as moment from 'moment';
import {Duration} from 'moment-mini';
import {RoundTimeOption} from '../features/project/project.model';

Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6212,12 +6212,7 @@ moment-duration-format@^2.2.2:
resolved "https://registry.yarnpkg.com/moment-duration-format/-/moment-duration-format-2.3.2.tgz#5fa2b19b941b8d277122ff3f87a12895ec0d6212"
integrity sha512-cBMXjSW+fjOb4tyaVHuaVE/A5TqkukDWiOfxxAjY+PEqmmBQlLwn+8OzwPiG3brouXKY5Un4pBjAeB6UToXHaQ==

moment-mini@^2.22.1:
version "2.22.1"
resolved "https://registry.yarnpkg.com/moment-mini/-/moment-mini-2.22.1.tgz#bc32d73e43a4505070be6b53494b17623183420d"
integrity sha512-OUCkHOz7ehtNMYuZjNciXUfwTuz8vmF1MTbAy59ebf+ZBYZO5/tZKuChVWCX+uDo+4idJBpGltNfV8st+HwsGw==

moment@>=2.14.0, moment@^2.10.2:
moment@>=2.14.0, moment@^2.10.2, moment@^2.24.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==
Expand Down

0 comments on commit 6b80062

Please sign in to comment.