Skip to content

Commit

Permalink
fix moment locale for en-us
Browse files Browse the repository at this point in the history
  • Loading branch information
kangzj committed Sep 19, 2024
1 parent 4851662 commit e0156ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion apps/odyssey-stats/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import currentUser from 'calypso/state/current-user/reducer';
import wpcomApiMiddleware from 'calypso/state/data-layer/wpcom-api-middleware';
import { setStore } from 'calypso/state/redux-store';
import sites from 'calypso/state/sites/reducer';
import { isSimpleSite } from 'calypso/state/sites/selectors';
import { combineReducers, addReducerEnhancer } from 'calypso/state/utils';
import config from './lib/config-api';
import initSentry from './lib/init-sentry';
Expand Down Expand Up @@ -46,6 +47,8 @@ async function AppBoot() {
},
};

const isSmiple = isSimpleSite( initialState, siteId );

const queryClient = new QueryClient();

const middlewares = [ thunkMiddleware, analyticsMiddleware, wpcomApiMiddleware as Middleware ];
Expand All @@ -70,7 +73,7 @@ async function AppBoot() {
}

// Ensure locale files are loaded before rendering.
setLocale( localeSlug ).then( () => {
setLocale( localeSlug, isSmiple ).then( () => {
registerStatsPages( window.location.pathname + window.location.search );

// HACK: getPathWithUpdatedQueryString filters duplicate query parameters added by `page.js`.
Expand Down
8 changes: 4 additions & 4 deletions apps/odyssey-stats/src/lib/set-locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const fixLongDateFormatForEn = ( localeSlug: string ) => {
}
};

const loadMomentLocale = async ( localeSlug: string, languageCode: string ) => {
const loadMomentLocale = async ( localeSlug: string, languageCode: string, isSimple: boolean ) => {
return import( `moment/locale/${ localeSlug }` )
.catch( ( error: Error ) => {
debug(
Expand All @@ -141,7 +141,7 @@ const loadMomentLocale = async ( localeSlug: string, languageCode: string ) => {
);
// Fallback 2 to the default US date time format.
// Interestingly `en` here represents `en-us` locale.
fixLongDateFormatForEn( localeSlug );
isSimple && fixLongDateFormatForEn( localeSlug );
localeSlug = DEFAULT_MOMENT_LOCALE;
} )
.then( () => moment.locale( localeSlug ) );
Expand All @@ -162,7 +162,7 @@ const loadLanguageFile = ( languageFileName: string ) => {
} );
};

export default ( localeSlug: string ) => {
export default ( localeSlug: string, isSimple = false ) => {
const languageCode = getLanguageCodeFromLocale( localeSlug );

// Load tranlation file if it's not English.
Expand All @@ -183,5 +183,5 @@ export default ( localeSlug: string ) => {

// We have to wait for moment locale to load before rendering the page, because otherwise the rendered date time wouldn't get re-rendered.
// This could be improved in the future with hooks.
return loadMomentLocale( localeSlug, languageCode );
return loadMomentLocale( localeSlug, languageCode, isSimple );
};

0 comments on commit e0156ea

Please sign in to comment.