Skip to content

Commit

Permalink
Remove usages of 'loc'
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Jan 24, 2024
1 parent 8225f9b commit 8d1528a
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/coding_scratchpad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function initCodingScratchpad(programmingLanguage: ProgrammingLanguage): void {
{
programmingLanguage: Papyros.toProgrammingLanguage(programmingLanguage),
standAlone: false,
locale: i18n.loc,
locale: i18n.locale(),
inputMode: InputMode.Interactive,
channelOptions: {
serviceWorkerName: "inputServiceWorker.js"
Expand Down
14 changes: 3 additions & 11 deletions app/assets/javascripts/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ export class I18n extends Polyglot {
constructor() {
super();
// set default locale, avoids a lot of errors when the locale is not yet set
this.loc = "en";
}

get loc(): string {
return this.locale();
}

set loc(locale: string) {
this.locale(locale);
this.locale("en");
}

/**
Expand All @@ -57,13 +49,13 @@ export class I18n extends Polyglot {
* Polyglot does not do custom number formatting, thus we use the javascript api
*/
formatNumber(number: number, options?: Record<string, unknown>): string {
return new Intl.NumberFormat(this.loc, options).format(number);
return new Intl.NumberFormat(this.locale(), options).format(number);
}

formatDate(date: string | number | Date | Dayjs, format: string): string {
const d = dayjs(date);
const f = super.t(format);
return d.locale(this.loc).format(f);
return d.locale(this.locale()).format(f);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/state/SavedAnnotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SavedAnnotationState extends State {
@stateProperty private byId = new StateMap<number, SavedAnnotation>();

private get url(): string {
return `/${i18n.loc}${URL}`;
return `/${i18n.locale()}${URL}`;
}

private async fetchList(url: string): Promise<Array<SavedAnnotation>> {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ type DatePickerOptions = {
*/
function initDatePicker(selector: string, options: DatePickerOptions = {}): object {
function init(): object {
if (i18n.loc === "nl") {
if (i18n.locale() === "nl") {
options.locale = Dutch;
}
return flatpickr(selector, options);
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/visualisations/series_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export abstract class SeriesGraph {
}

private getUrl(): string {
return `/${i18n.loc}${this.baseUrl}${this.seriesId}`;
return `/${i18n.locale()}${this.baseUrl}${this.seriesId}`;
}


Expand Down
2 changes: 1 addition & 1 deletion app/views/activities/description.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
</div>
<script>
i18n = dodona.i18n || {};
i18n.loc = "<%= I18n.locale %>";
i18n.locale("<%= I18n.locale %>");
dodona.ready.then(() => window.dodona.initDescription());
</script>
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</div>
<script>
i18n = dodona.i18n || {};
i18n.loc = "<%= I18n.locale %>";
i18n.locale("<%= I18n.locale %>");
dodona.checkTimeZone(<%= @time_zone_offset %>);
dodona.checkIframe();
</script>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/lti.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<section class="toasts"></section>
<script>
i18n = dodona.i18n || {};
i18n.loc = "<%= I18n.locale %>";
i18n.locale("<%= I18n.locale %>");
dodona.checkTimeZone(<%= @time_zone_offset %>);
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion test/javascript/visualisations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ beforeAll(() => {
null, "Jan", "Feb", "Mrt", "Apr", "Mei", "Jun",
"Jul", "Aug", "Sep", "Okt", "Nov", "Dec"]
}[arg]) as string[]);
i18n.loc = "nl";
i18n.locale("nl");


document.body.innerHTML = "" +
Expand Down

0 comments on commit 8d1528a

Please sign in to comment.