mirror of
https://github.com/WowUp/WowUp.git
synced 2026-04-23 15:27:03 -04:00
More number issues for translations
This commit is contained in:
@@ -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>
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
15
wowup-electron/src/app/utils/number.utils.ts
Normal file
15
wowup-electron/src/app/utils/number.utils.ts
Normal 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);
|
||||
}
|
||||
@@ -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 сообщества.",
|
||||
|
||||
Reference in New Issue
Block a user