mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-19 19:21:33 +10:00
fix(i18n): delete local translations
This commit is contained in:
35
apps/server/src/translation/translation.controller.ts
Normal file
35
apps/server/src/translation/translation.controller.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { HttpService } from "@nestjs/axios";
|
||||
import { Controller, Get, Header, Param } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
|
||||
import { Config } from "../config/schema";
|
||||
import { UtilsService } from "../utils/utils.service";
|
||||
|
||||
@Controller("translation")
|
||||
export class TranslationController {
|
||||
constructor(
|
||||
private readonly httpService: HttpService,
|
||||
private readonly configService: ConfigService<Config>,
|
||||
private readonly utils: UtilsService,
|
||||
) {}
|
||||
|
||||
private async fetchTranslations(locale: string) {
|
||||
const distributionHash = this.configService.get("CROWDIN_DISTRIBUTION_HASH");
|
||||
const response = await this.httpService.axiosRef.get(
|
||||
`https://distributions.crowdin.net/${distributionHash}/content/${locale}/messages.json`,
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
@Get("/:locale")
|
||||
@Header("Content-Type", "application/octet-stream")
|
||||
@Header("Content-Disposition", 'attachment; filename="messages.po"')
|
||||
async getTranslation(@Param("locale") locale: string) {
|
||||
return this.utils.getCachedOrSet(
|
||||
`translation:${locale}`,
|
||||
async () => this.fetchTranslations(locale),
|
||||
1000 * 60 * 60 * 24, // 24 hours
|
||||
);
|
||||
}
|
||||
}
|
||||
10
apps/server/src/translation/translation.module.ts
Normal file
10
apps/server/src/translation/translation.module.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { HttpModule } from "@nestjs/axios";
|
||||
import { Module } from "@nestjs/common";
|
||||
|
||||
import { TranslationController } from "./translation.controller";
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule],
|
||||
controllers: [TranslationController],
|
||||
})
|
||||
export class TranslationModule {}
|
||||
Reference in New Issue
Block a user