Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Chinese Language Support & Fix Issue with Asset File Names #47

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion api/src/__tests__/getPosterTypeDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,39 @@ describe('getPosterTypeDetails', () => {
});
});
});
describe('Chinese', () => {
describe('Simplified Chinese', () => {
it('handles a string where original poster is not first', () => {
const result = getPosterTypeDetails('频繁发帖人、原始发帖人');

expect(result).toEqual({
isAuthor: true,
isFrequentPoster: true,
isMostRecentPoster: false,
});
});

it('handles all three types', () => {
const result = getPosterTypeDetails(
'原始发帖人、 最新发帖人、 频繁发帖人',
);
expect(result).toEqual({
isAuthor: true,
isFrequentPoster: true,
isMostRecentPoster: true,
});
});
it('handles multiple spaces between entries', () => {
const result = getPosterTypeDetails(
' 原始发帖人、 最新发帖人、 频繁发帖人 ',
);
expect(result).toEqual({
isAuthor: true,
isFrequentPoster: true,
isMostRecentPoster: true,
});
});
});
describe('Traditional Chinese', () => {
it('handles a string where original poster is not first', () => {
const result = getPosterTypeDetails('頻繁發文者、原始作者');

Expand Down
17 changes: 15 additions & 2 deletions api/src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../types';

// source: github.com:discourse/discourse -> config/locales/server.en.yml
// source: github.com:discourse/discourse -> config/locales/server.zh_TW.yml
// source: github.com:discourse/discourse -> config/locales/server.zh_CN.yml
// key: `poster_description_joiner`
export const i18nSeparatorsRegex = /,|、/;

Expand All @@ -17,8 +17,19 @@ const i18nPosterTypes = {
'most recent poster': MostRecentPoster.value,
'frequent poster': FrequentPoster.value,
},
// source: github.com:discourse/discourse -> config/locales/server.zh_TW.yml
// source: github.com:discourse/discourse -> config/locales/server.zh_CN.yml
zh: {
原始发帖人: OriginalPoster.value,
最新发帖人: MostRecentPoster.value,
频繁发帖人: FrequentPoster.value,
},
zh_cn: {
原始发帖人: OriginalPoster.value,
最新发帖人: MostRecentPoster.value,
频繁发帖人: FrequentPoster.value,
},
// source: github.com:discourse/discourse -> config/locales/server.zh_TW.yml
zh_tw: {
原始作者: OriginalPoster.value,
當前大部分貼文作者: MostRecentPoster.value,
頻繁發文者: FrequentPoster.value,
Expand All @@ -28,6 +39,8 @@ const i18nPosterTypes = {
const posterTypeMap: Record<string, PosterType> = {
...i18nPosterTypes.en,
...i18nPosterTypes.zh,
...i18nPosterTypes.zh_cn,
...i18nPosterTypes.zh_tw,
};

export const getPosterType = (type: string): PosterType | undefined => {
Expand Down
Loading