@@ -30,8 +30,10 @@ type CategoryDataT = {
3030}
3131
3232type RestDataT = {
33- [ version : string ] : {
34- [ category : string ] : CategoryDataT
33+ [ language : string ] : {
34+ [ version : string ] : {
35+ [ category : string ] : CategoryDataT
36+ }
3537 }
3638}
3739
@@ -91,22 +93,37 @@ export const getServerSideProps: GetServerSideProps<Props> = async (context) =>
9193 // e.g. the `activity` from `/en/rest/reference/activity#events`
9294 const category = context . params ! . category as string
9395 const currentVersion = context . params ! . versionId as string
96+ const currentLanguage = req . context . currentLanguage as string
9497
9598 // Use a local cache to store all of the REST operations, so
9699 // we only read the directory of static/decorated files once
97100 if ( ! rest ) {
98101 rest = ( await getRest ( ) ) as RestOperationsT
99102 }
100103
104+ /* This sets up a skeleton object in the format:
105+ {
106+ 'en': { free-pro-team@latest : {}, enterprise-cloud@latest: {} },
107+ 'ja': { free-pro-team@latest : {}, enterprise-cloud@latest: {} }
108+ }
109+ */
101110 if ( ! restOperationData ) {
102111 restOperationData = { }
103- Object . keys ( req . context . allVersions ) . forEach ( ( version ) => ( restOperationData ! [ version ] = { } ) )
112+ Object . keys ( req . context . languages ) . forEach ( ( language ) => {
113+ restOperationData ! [ language ] = { }
114+ Object . keys ( req . context . allVersions ) . forEach (
115+ ( version ) => ( restOperationData ! [ language ] [ version ] = { } )
116+ )
117+ } )
104118 }
105119
106120 const restOperations = rest [ currentVersion ] [ category ]
107121
108- if ( ! ( category in restOperationData [ currentVersion ] ) ) {
109- restOperationData [ currentVersion ] [ category ] = ( await getRestOperationData (
122+ // The context passed will have the Markdown content for the language
123+ // of the page being requested and the Markdown will be rendered
124+ // using the `currentVersion`
125+ if ( ! ( category in restOperationData [ currentLanguage ] [ currentVersion ] ) ) {
126+ restOperationData [ currentLanguage ] [ currentVersion ] [ category ] = ( await getRestOperationData (
110127 category ,
111128 restOperations ,
112129 req . context
@@ -118,15 +135,16 @@ export const getServerSideProps: GetServerSideProps<Props> = async (context) =>
118135 // are undefined. We need to populate those properties with the static
119136 // data read from the decorated schema files.
120137 const articleContext = getArticleContextFromRequest ( req )
121- articleContext . miniTocItems = restOperationData [ currentVersion ] [ category ] . miniTocItems
138+ articleContext . miniTocItems =
139+ restOperationData [ currentLanguage ] [ currentVersion ] [ category ] . miniTocItems
122140
123141 return {
124142 props : {
125143 restOperations,
126144 mainContext : getMainContext ( req , res ) ,
127- descriptions : restOperationData [ currentVersion ] [ category ] . descriptions ,
145+ descriptions : restOperationData [ currentLanguage ] [ currentVersion ] [ category ] . descriptions ,
128146 articleContext : articleContext ,
129- introContent : restOperationData [ currentVersion ] [ category ] . introContent ,
147+ introContent : restOperationData [ currentLanguage ] [ currentVersion ] [ category ] . introContent ,
130148 } ,
131149 }
132150}
0 commit comments