mirror of
https://github.com/NicolasConstant/sengi
synced 2024-12-22 21:58:59 +01:00
Merge pull request #610 from NicolasConstant/topic_enhance-language-feature
Topic enhance language feature
This commit is contained in:
commit
a0cb240446
@ -68,6 +68,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||
this.detectAutosuggestion(value);
|
||||
this._status = value;
|
||||
|
||||
this.languageService.autoDetectLang(value);
|
||||
|
||||
setTimeout(() => {
|
||||
this.autoGrow();
|
||||
}, 0);
|
||||
|
@ -62,12 +62,20 @@
|
||||
<a href (click)="onRemoveLang(l)" class="form-button language__entry__action sound__play">remove</a>
|
||||
</div>
|
||||
<input type="text" (input)="onSearchLang($event.target.value)" [(ngModel)]="searchLang"
|
||||
placeholder="Find Language" autocomplete="off" class="form-control form-control-sm language__search"/>
|
||||
placeholder="Find Language" autocomplete="off"
|
||||
class="form-control form-control-sm language__search" />
|
||||
<div *ngFor="let l of searchedLangs" class="language__entry">
|
||||
<span class="language__entry__name">{{ l.name }} ({{l.iso639}})</span>
|
||||
<a href (click)="onAddLang(l)" class="form-button language__entry__action sound__play">add</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<input class="sub-section__checkbox" [(ngModel)]="disableLangAutodetectEnabled"
|
||||
(change)="onDisableLangAutodetectChanged()" type="checkbox" name="disableLangAutodetec"
|
||||
value="disableLangAutodetec" id="disableLangAutodetec">
|
||||
<label class="noselect sub-section__label" for="disableLangAutodetec">disable language autodetection</label>
|
||||
</div>
|
||||
<h4 class="panel__subtitle">Twitter Bridge</h4>
|
||||
<div class="sub-section">
|
||||
@ -159,7 +167,8 @@
|
||||
|
||||
<input class="sub-section__checkbox" [checked]="timeLineHeader === 6" (change)="onTimeLineHeaderChange(6)"
|
||||
type="radio" name="timelineheader-6" value="timelineheader-6" id="timelineheader-6">
|
||||
<label class="noselect sub-section__label" for="timelineheader-6">Title - Account Icon - Username - Domain Name</label>
|
||||
<label class="noselect sub-section__label" for="timelineheader-6">Title - Account Icon - Username - Domain
|
||||
Name</label>
|
||||
<br>
|
||||
|
||||
<span class="sub-section__title">loading behavior:</span><br />
|
||||
@ -186,7 +195,8 @@
|
||||
<input class="sub-section__checkbox" [(ngModel)]="autoFollowOnListEnabled"
|
||||
(change)="onAutoFollowOnListChanged()" type="checkbox" name="onAutoFollowOnListChanged"
|
||||
value="onAutoFollowOnListChanged" id="onAutoFollowOnListChanged">
|
||||
<label class="noselect sub-section__label" for="onAutoFollowOnListChanged">autofollow accounts when adding to list</label>
|
||||
<label class="noselect sub-section__label" for="onAutoFollowOnListChanged">autofollow accounts when
|
||||
adding to list</label>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
@ -199,6 +209,17 @@
|
||||
<label class="noselect sub-section__label" for="disableRemoteFetching">disable remote status
|
||||
fetching</label>
|
||||
<br>
|
||||
|
||||
<input class="sub-section__checkbox" [(ngModel)]="enableAltLabelEnabled"
|
||||
(change)="onEnableAltLabelChanged()" type="checkbox" name="enableAltLabel"
|
||||
value="enableAltLabel" id="enableAltLabel">
|
||||
<label class="noselect sub-section__label" for="enableAltLabel">enable alt label</label>
|
||||
<br>
|
||||
|
||||
<input class="sub-section__checkbox" [(ngModel)]="enableFreezeAvatarEnabled"
|
||||
(change)="onEnableFreezeAvatarChanged()" type="checkbox" name="enableFreezeAvatar"
|
||||
value="enableFreezeAvatar" id="enableFreezeAvatar">
|
||||
<label class="noselect sub-section__label" for="enableFreezeAvatar">freeze animated avatar</label>
|
||||
</div>
|
||||
|
||||
<h4 class="panel__subtitle">About</h4>
|
||||
|
@ -29,6 +29,9 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
||||
disableRemoteStatusFetchingEnabled: boolean;
|
||||
disableAvatarNotificationsEnabled: boolean;
|
||||
disableSoundsEnabled: boolean;
|
||||
disableLangAutodetectEnabled: boolean;
|
||||
enableAltLabelEnabled: boolean;
|
||||
enableFreezeAvatarEnabled: boolean;
|
||||
version: string;
|
||||
|
||||
hasPleromaAccount: boolean;
|
||||
@ -146,6 +149,9 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
||||
this.twitterBridgeInstance = settings.twitterBridgeInstance;
|
||||
|
||||
this.configuredLangs = this.languageService.getConfiguredLanguages();
|
||||
this.disableLangAutodetectEnabled = settings.disableLangAutodetec;
|
||||
this.enableAltLabelEnabled = settings.enableAltLabel;
|
||||
this.enableFreezeAvatarEnabled = settings.enableFreezeAvatar;
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
@ -273,6 +279,27 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
||||
return false;
|
||||
}
|
||||
|
||||
onEnableFreezeAvatarChanged(){
|
||||
this.notifyRestartNeeded();
|
||||
let settings = this.settingsService.getSettings();
|
||||
settings.enableFreezeAvatar = this.enableFreezeAvatarEnabled;
|
||||
this.settingsService.saveSettings(settings);
|
||||
}
|
||||
|
||||
onEnableAltLabelChanged(){
|
||||
this.notifyRestartNeeded();
|
||||
let settings = this.settingsService.getSettings();
|
||||
settings.enableAltLabel = this.enableAltLabelEnabled;
|
||||
this.settingsService.saveSettings(settings);
|
||||
}
|
||||
|
||||
onDisableLangAutodetectChanged() {
|
||||
this.notifyRestartNeeded();
|
||||
let settings = this.settingsService.getSettings();
|
||||
settings.disableLangAutodetec = this.disableLangAutodetectEnabled;
|
||||
this.settingsService.saveSettings(settings);
|
||||
}
|
||||
|
||||
onDisableAutofocusChanged() {
|
||||
this.notifyRestartNeeded();
|
||||
let settings = this.settingsService.getSettings();
|
||||
|
@ -1,4 +1,5 @@
|
||||
<div class="image">
|
||||
<div class="image">
|
||||
<div class="image__alt" *ngIf="displayAltLabel">ALT</div>
|
||||
<a href class="image__link" (click)="openExternal()" (auxclick)="openExternal()" title="open image">
|
||||
<fa-icon class="image__link--icon" [icon]="faLink"></fa-icon>
|
||||
</a>
|
||||
|
@ -29,6 +29,24 @@
|
||||
opacity: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&__alt {
|
||||
display: inline;
|
||||
color: white;
|
||||
|
||||
z-index: 10;
|
||||
|
||||
position: absolute;
|
||||
bottom: 5px;
|
||||
left: 5px;
|
||||
|
||||
font-size: 10px;
|
||||
font-weight: bolder;
|
||||
|
||||
background-color: rgba($color: #000000, $alpha: 0.5);
|
||||
border-radius: 3px;
|
||||
padding: 2px 5px;
|
||||
}
|
||||
}
|
||||
|
||||
img,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { faLink } from "@fortawesome/free-solid-svg-icons";
|
||||
|
||||
import { SettingsService } from '../../../../../services/settings.service';
|
||||
import { Attachment } from '../../../../../services/models/mastodon.interfaces';
|
||||
|
||||
@Component({
|
||||
@ -10,11 +11,16 @@ import { Attachment } from '../../../../../services/models/mastodon.interfaces';
|
||||
})
|
||||
export class AttachementImageComponent implements OnInit {
|
||||
faLink = faLink;
|
||||
displayAltLabel: boolean;
|
||||
|
||||
@Input() attachment: Attachment;
|
||||
@Output() openEvent = new EventEmitter();
|
||||
|
||||
constructor() { }
|
||||
constructor(
|
||||
private readonly settingsService: SettingsService
|
||||
) {
|
||||
this.displayAltLabel = this.settingsService.getSettings().enableAltLabel;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ export class StatusTranslateComponent implements OnInit, OnDestroy {
|
||||
.then(canTranslate => {
|
||||
if (canTranslate
|
||||
&& !this.status.isRemote
|
||||
&& this.status.status.language
|
||||
&& this.configuredLanguages.length > 0
|
||||
&& this.configuredLanguages.findIndex(x => x.iso639 === this.status.status.language) === -1) {
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="reblog" *ngIf="reblog">
|
||||
<a class="reblog__profile-link" href title="{{ status.account.acct }}"
|
||||
(click)="openAccount(status.account)"
|
||||
(auxclick)="openUrl(status.account.url)"><span innerHTML="{{ status.account | accountEmoji }}"></span> <img *ngIf="reblog" class="reblog__avatar" src="{{ status.account.avatar | ensureHttps }}" /></a> boosted
|
||||
(auxclick)="openUrl(status.account.url)"><span innerHTML="{{ status.account | accountEmoji }}"></span> <img *ngIf="reblog" class="reblog__avatar" src="{{ getAvatar(status.account) | ensureHttps }}" /></a> boosted
|
||||
</div>
|
||||
<div *ngIf="statusWrapper.status.pinned && !notificationType" class="pinned">
|
||||
<div class="notification--icon">
|
||||
@ -60,9 +60,9 @@
|
||||
<div [ngClass]="{'notification--status': notificationAccount }">
|
||||
<a href class="status__profile-link" title="{{displayedStatus.account.acct}}"
|
||||
(click)="openAccount(displayedStatus.account)" (auxclick)="openUrl(displayedStatus.account.url)">
|
||||
<img [class.status__avatar--boosted]="reblog || notificationAccount" class="status__avatar" src="{{ displayedStatus.account.avatar | ensureHttps }}" />
|
||||
<img [class.status__avatar--boosted]="reblog || notificationAccount" class="status__avatar" src="{{ getAvatar(displayedStatus.account) | ensureHttps }}" />
|
||||
<!-- <img *ngIf="reblog" class="status__avatar--reblog" src="{{ status.account.avatar }}" /> -->
|
||||
<img *ngIf="notificationAccount" class="notification--avatar" src="{{ notificationAccount.avatar | ensureHttps }}" />
|
||||
<img *ngIf="notificationAccount" class="notification--avatar" src="{{ getAvatar(notificationAccount) | ensureHttps }}" />
|
||||
<span class="status__name">
|
||||
<span class="status__name--displayname"
|
||||
innerHTML="{{displayedStatus.account | accountEmoji}}"></span><span
|
||||
|
@ -10,6 +10,7 @@ import { EmojiConverter, EmojiTypeEnum } from '../../../tools/emoji.tools';
|
||||
import { ContentWarningPolicyEnum } from '../../../states/settings.state';
|
||||
import { StatusesStateService, StatusState } from "../../../services/statuses-state.service";
|
||||
import { DatabindedTextComponent } from "./databinded-text/databinded-text.component";
|
||||
import { SettingsService } from "../../../services/settings.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-status",
|
||||
@ -44,6 +45,8 @@ export class StatusComponent implements OnInit {
|
||||
isSelected: boolean;
|
||||
isRemote: boolean;
|
||||
|
||||
private freezeAvatarEnabled: boolean;
|
||||
|
||||
hideStatus: boolean = false;
|
||||
|
||||
@Output() browseAccountEvent = new EventEmitter<string>();
|
||||
@ -103,6 +106,7 @@ export class StatusComponent implements OnInit {
|
||||
constructor(
|
||||
public elem: ElementRef,
|
||||
private readonly toolsService: ToolsService,
|
||||
private readonly settingsService: SettingsService,
|
||||
private readonly statusesStateService: StatusesStateService) { }
|
||||
|
||||
ngOnInit() {
|
||||
@ -111,12 +115,22 @@ export class StatusComponent implements OnInit {
|
||||
this.statusWrapper = notification.editedStatus;
|
||||
}
|
||||
});
|
||||
|
||||
this.freezeAvatarEnabled = this.settingsService.getSettings().enableFreezeAvatar;
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.statusesStateServiceSub) this.statusesStateServiceSub.unsubscribe();
|
||||
}
|
||||
|
||||
getAvatar(acc: Account): string {
|
||||
if(this.freezeAvatarEnabled){
|
||||
return acc.avatar_static;
|
||||
} else {
|
||||
return acc.avatar;
|
||||
}
|
||||
}
|
||||
|
||||
private ensureMentionAreDisplayed(data: string): string {
|
||||
const mentions = this.displayedStatus.mentions;
|
||||
if (!mentions || mentions.length === 0) return data;
|
||||
|
@ -30,7 +30,7 @@ export class TimeAgoPipe implements PipeTransform {
|
||||
const hours = minutes / 60;
|
||||
const days = hours / 24;
|
||||
// const months = days / 30.416;
|
||||
// const years = days / 365;
|
||||
const years = days / 365;
|
||||
|
||||
if (seconds <= 59) {
|
||||
text = Math.round(seconds) + 's';
|
||||
@ -38,8 +38,10 @@ export class TimeAgoPipe implements PipeTransform {
|
||||
text = Math.round(minutes) + 'm';
|
||||
} else if (hours <= 23) {
|
||||
text = Math.round(hours) + 'h';
|
||||
} else {
|
||||
} else if (days < 365) {
|
||||
text = Math.round(days) + 'd';
|
||||
} else {
|
||||
text = Math.round(years) + 'y';
|
||||
}
|
||||
|
||||
if (minutes < 1) {
|
||||
|
@ -1,10 +1,30 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MyElectronService {
|
||||
detectedLangSubject = new Subject<DetectedLang[]>();
|
||||
|
||||
constructor() {
|
||||
try {
|
||||
if ((<any>window).api) {
|
||||
(<any>window).api.receive("detectedLang", (data) => {
|
||||
const result = [];
|
||||
for (const l of data) {
|
||||
let newLang = new DetectedLang(l[0], l[1]);
|
||||
result.push(newLang);
|
||||
}
|
||||
this.detectedLangSubject.next(result);
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
this.detectLang("ceci est une phrase");
|
||||
}
|
||||
|
||||
setLang(lang: string) {
|
||||
@ -17,4 +37,22 @@ export class MyElectronService {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
detectLang(text: string) {
|
||||
try {
|
||||
if ((<any>window).api) {
|
||||
(<any>window).api.send("detectLang", text);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class DetectedLang {
|
||||
constructor(
|
||||
public lang: string,
|
||||
public score: number
|
||||
) {}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
|
||||
import { ILanguage } from '../states/settings.state';
|
||||
import { MyElectronService } from './electron.service';
|
||||
import { DetectedLang, MyElectronService } from './electron.service';
|
||||
import { SettingsService } from './settings.service';
|
||||
|
||||
@Injectable({
|
||||
@ -19,6 +19,42 @@ export class LanguageService {
|
||||
) {
|
||||
this.configuredLanguagesChanged.next(this.getConfiguredLanguages());
|
||||
this.selectedLanguageChanged.next(this.getSelectedLanguage());
|
||||
|
||||
this.electronService.detectedLangSubject.subscribe(l => {
|
||||
this.detectedLanguage(l);
|
||||
});
|
||||
}
|
||||
|
||||
private detectedLanguage(lang: DetectedLang[]) {
|
||||
if (!lang) return;
|
||||
|
||||
if (lang.length >= 1) {
|
||||
const languages = this.getConfiguredLanguages();
|
||||
|
||||
let firstLang = lang[0].lang;
|
||||
let firstLocalLang = languages.find(x => x.iso639 == firstLang);
|
||||
if (firstLocalLang) {
|
||||
this.setSelectedLanguage(firstLocalLang);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lang.length > 1) {
|
||||
firstLang = lang[1].lang;
|
||||
firstLocalLang = languages.find(x => x.iso639 == firstLang);
|
||||
if (firstLocalLang) {
|
||||
this.setSelectedLanguage(firstLocalLang);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
autoDetectLang(text: string): void {
|
||||
if (!text || text.length < 5) return;
|
||||
|
||||
if (!this.settingsService.getSettings().disableLangAutodetec) {
|
||||
this.electronService.detectLang(text);
|
||||
}
|
||||
}
|
||||
|
||||
getSelectedLanguage(): ILanguage {
|
||||
|
@ -84,6 +84,10 @@ export class GlobalSettings {
|
||||
|
||||
configuredLanguages: ILanguage[] = [];
|
||||
selectedLanguage: ILanguage;
|
||||
disableLangAutodetec: boolean;
|
||||
|
||||
enableAltLabel: boolean;
|
||||
enableFreezeAvatar: boolean;
|
||||
}
|
||||
|
||||
export interface ILanguage {
|
||||
@ -181,6 +185,9 @@ export class SettingsState {
|
||||
newSettings.twitterBridgeInstance = oldSettings.twitterBridgeInstance;
|
||||
newSettings.configuredLanguages = oldSettings.configuredLanguages;
|
||||
newSettings.selectedLanguage = oldSettings.selectedLanguage;
|
||||
newSettings.disableLangAutodetec = oldSettings.disableLangAutodetec;
|
||||
newSettings.enableAltLabel = oldSettings.enableAltLabel;
|
||||
newSettings.enableFreezeAvatar = oldSettings.enableFreezeAvatar;
|
||||
|
||||
return newSettings;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user