Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
type Item =
| string
| number
| {
props?: {
children?: Item | Item[];
href?: string;
};
};
// Extract nested strings from a translated string
export function extractStrings( item: Item, result: string = '' ): string {
if ( typeof item === 'string' || typeof item === 'number' ) {
result += item;
} else if ( item?.props ) {
if ( Array.isArray( item.props.children ) ) {
for ( const child of item.props.children ) {
result = extractStrings( child, result );
}
} else if ( item.props.children ) {
result = extractStrings( item.props.children, result );
}
if ( item.props.href ) {
result += `: ${ item.props.href }`;
}
}
return result;
}