More number issues for translations

This commit is contained in:
jliddev
2020-11-20 14:07:14 -06:00
parent 3b6366ebbf
commit e070c60285
6 changed files with 44 additions and 50 deletions

View File

@@ -6,23 +6,10 @@
<p>{{ "DIALOGS.INSTALL_FROM_URL.SUPPORTED_SOURCES" | translate }}</p>
<mat-form-field class="url-input-container">
<mat-label>{{ "DIALOGS.INSTALL_FROM_URL.ADDON_URL_INPUT_LABEL" | translate }}</mat-label>
<input
matInput
[placeholder]="'DIALOGS.INSTALL_FROM_URL.ADDON_URL_INPUT_PLACEHOLDER' | translate"
[(ngModel)]="query"
(keyup.enter)="onImportUrl()"
[disabled]="isBusy === true"
/>
<button
mat-button
color="accent"
*ngIf="query"
matSuffix
mat-icon-button
aria-label="Clear"
(click)="onClearSearch()"
[disabled]="isBusy === true"
>
<input matInput [placeholder]="'DIALOGS.INSTALL_FROM_URL.ADDON_URL_INPUT_PLACEHOLDER' | translate"
[(ngModel)]="query" (keyup.enter)="onImportUrl()" [disabled]="isBusy === true" />
<button mat-button color="accent" *ngIf="query" matSuffix mat-icon-button aria-label="Clear"
(click)="onClearSearch()" [disabled]="isBusy === true">
<mat-icon svgIcon="fas:times"></mat-icon>
</button>
</mat-form-field>
@@ -35,15 +22,7 @@
<h4>{{ addon.name }}</h4>
<p>{{ addon.author }}</p>
<p class="addon-download-count">
{{
"DIALOGS.INSTALL_FROM_URL.DOWNLOAD_COUNT"
| translate
: {
count: addon.downloadCount,
textCount: (addon.downloadCount | downloadCount),
provider: addon.providerName
}
}}
{{ "DIALOGS.INSTALL_FROM_URL.DOWNLOAD_COUNT" | translate: getDownloadCountParams() }}
</p>
</div>
<div class="install-container">
@@ -66,16 +45,8 @@
<button mat-button (click)="onClose()">
{{ "DIALOGS.INSTALL_FROM_URL.CLOSE_BUTTON" | translate }}
</button>
<button
mat-flat-button
color="primary"
cdkFocusInitial
(click)="onImportUrl()"
appUserActionTracker
category="InstallFromUrl"
action="ImportUrl"
[label]="query"
>
<button mat-flat-button color="primary" cdkFocusInitial (click)="onImportUrl()" appUserActionTracker
category="InstallFromUrl" action="ImportUrl" [label]="query">
{{ "DIALOGS.INSTALL_FROM_URL.IMPORT_BUTTON" | translate }}
</button>
</div>
</div>

View File

@@ -7,6 +7,8 @@ import { AddonService } from "../../services/addons/addon.service";
import { SessionService } from "../../services/session/session.service";
import { AlertDialogComponent } from "../alert-dialog/alert-dialog.component";
import { TranslateService } from "@ngx-translate/core";
import { roundDownloadCount, shortenDownloadCount } from "../../utils/number.utils";
import { DownloadCountPipe } from "app/pipes/download-count.pipe";
@Component({
selector: "app-install-from-url-dialog",
@@ -28,6 +30,7 @@ export class InstallFromUrlDialogComponent implements OnInit, OnDestroy {
private _dialog: MatDialog,
private _sessionService: SessionService,
private _translateService: TranslateService,
private _downloadCountPipe: DownloadCountPipe,
public dialogRef: MatDialogRef<InstallFromUrlDialogComponent>
) {}
@@ -66,6 +69,18 @@ export class InstallFromUrlDialogComponent implements OnInit, OnDestroy {
});
}
public getDownloadCountParams() {
const count = 1000;
return {
count,
shortCount: roundDownloadCount(count),
simpleCount: shortenDownloadCount(count, 1),
myriadCount: shortenDownloadCount(count, 4),
textCount: this._downloadCountPipe.transform(count),
provider: this.addon.providerName,
};
}
async onImportUrl() {
this.addon = undefined;
this.showInstallSuccess = false;

View File

@@ -63,6 +63,6 @@ import { HomeComponent } from "./home.component";
OptionsDebugSectionComponent,
],
imports: [CommonModule, SharedModule, HomeRoutingModule, MatModule, DirectiveModule],
providers: [DatePipe, GetAddonListItemFilePropPipe],
providers: [DatePipe, GetAddonListItemFilePropPipe, DownloadCountPipe],
})
export class HomeModule {}

View File

@@ -1,6 +1,6 @@
import { DecimalPipe, formatNumber } from "@angular/common";
import { Pipe, PipeTransform } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";
import { shortenDownloadCount } from "../utils/number.utils";
@Pipe({
name: "downloadCount",
@@ -8,22 +8,15 @@ import { TranslateService } from "@ngx-translate/core";
export class DownloadCountPipe implements PipeTransform {
constructor(private translateService: TranslateService) {}
shortenDownloadCount(value: number, nDigit: number): string {
const exponent = Math.log10(value);
const nGroups = Math.floor(exponent / nDigit);
const shortValue = value / Math.pow(10, nGroups * nDigit);
return shortValue.toFixed(0);
}
transform(value: number, ...args: unknown[]): string {
const numMatches = /(e\+\d+)/.exec(value.toExponential());
const suffix = numMatches[1];
return suffix
? this.translateService.instant("COMMON.DOWNLOAD_COUNT." + suffix, {
count: this.shortenDownloadCount(value, 3),
simpleCount: this.shortenDownloadCount(value, 1),
myriadCount: this.shortenDownloadCount(value, 4),
count: shortenDownloadCount(value, 3),
simpleCount: shortenDownloadCount(value, 1),
myriadCount: shortenDownloadCount(value, 4),
})
: value.toString();
}

View File

@@ -0,0 +1,15 @@
export function shortenDownloadCount(value: number, nDigit: number): string {
const exponent = Math.log10(value);
const nGroups = Math.floor(exponent / nDigit);
const shortValue = value / Math.pow(10, nGroups * nDigit);
return shortValue.toFixed(0);
}
// This is a horrifying way to round to the nearest tens place
export function roundDownloadCount(value: number): number {
const exp = value.toExponential();
const numberMatch = /(\d*\.?\d*)e\+(\d+)/.exec(exp);
const number = Math.ceil(parseFloat(numberMatch[1]) * 10);
const exponent = new Array(parseInt(numberMatch[2]) - 1).fill(0);
return parseInt(`${number}${exponent.join("")}`, 10);
}

View File

@@ -113,7 +113,7 @@
"ADDON_URL_INPUT_PLACEHOLDER": "Например ссылки GitHub или WowInterface",
"CLOSE_BUTTON": "Закрыть",
"DESCRIPTION": "Если вы хотите установить модификацию непосредственно по ссылке, вставьте её ниже, чтобы начать.",
"DOWNLOAD_COUNT": "{textCount} {count, plural, one{загрузка} few{загрузки} other{загрузок}} на {provider}",
"DOWNLOAD_COUNT": "{textCount} {shortCount, plural, one{загрузка} few{загрузки} other{загрузок}} на {provider}",
"ERROR": {
"FAILED_TO_CONNECT": "Не удается подключиться к API, подождите немного и повторите попытку.",
"INSTALL_FAILED": "Что-то пошло не так при попытке установить модификацию, попытайтесь снова.\n\nЕсли это сообщение продолжает появляться, вы можете получить помощь в канале #wowup-support нашего Discord сообщества.",