@@ -50,6 +50,7 @@ export interface TranslationsDoc {
50
50
linkedAt : Timestamp ;
51
51
linkedBy : string ;
52
52
} ;
53
+ tags ?: string [ ] ;
53
54
} ;
54
55
strings : TranslationsMap ;
55
56
}
@@ -482,6 +483,9 @@ export class RootCMSClient {
482
483
} ) ;
483
484
batchCount += 1 ;
484
485
486
+ this . publishTranslationsDoc ( doc . id , { batch} ) ;
487
+ batchCount += 2 ;
488
+
485
489
publishedDocs . push ( doc ) ;
486
490
487
491
if ( batchCount >= 400 ) {
@@ -594,6 +598,9 @@ export class RootCMSClient {
594
598
} ) ;
595
599
batchCount += 1 ;
596
600
601
+ this . publishTranslationsDoc ( doc . id , { batch} ) ;
602
+ batchCount += 2 ;
603
+
597
604
publishedDocs . push ( doc ) ;
598
605
599
606
if ( batchCount >= 400 ) {
@@ -635,6 +642,48 @@ export class RootCMSClient {
635
642
}
636
643
}
637
644
645
+ async publishTranslationsDoc (
646
+ translationsId : string ,
647
+ options ?: { batch ?: WriteBatch ; publishedBy ?: string }
648
+ ) {
649
+ const docSlug = translationsId . replaceAll ( '/' , '--' ) ;
650
+ const draftRef = this . db . doc (
651
+ `Projects/${ this . projectId } /TranslationsManager/draft/Translations/${ docSlug } `
652
+ ) ;
653
+ const snapshot = await draftRef . get ( ) ;
654
+
655
+ if ( ! snapshot . exists ) {
656
+ // Ignore missing translations.
657
+ console . warn ( `translations ${ translationsId } does not exist` ) ;
658
+ return ;
659
+ }
660
+
661
+ // If the translations publishing is tied to another batch request (e.g. doc
662
+ // publishing), the batch request will be committed upstream.
663
+ const commitBatch = ! options ?. batch ;
664
+
665
+ const batch = options ?. batch || this . db . batch ( ) ;
666
+ batch . update ( draftRef , {
667
+ 'sys.publishedAt' : Timestamp . now ( ) ,
668
+ 'sys.publishedBy' : options ?. publishedBy || 'root-cms-client' ,
669
+ } ) ;
670
+
671
+ const publishedRef = this . db . doc (
672
+ `Projects/${ this . projectId } /TranslationsManager/published/Translations/${ docSlug } `
673
+ ) ;
674
+ const data = { ...snapshot . data ( ) } ;
675
+ if ( ! data . sys ) {
676
+ data . sys = { } ;
677
+ }
678
+ data . sys . publishedAt = Timestamp . now ( ) ;
679
+ data . sys . publishedBy = options ?. publishedBy || 'root-cms-client' ;
680
+ batch . set ( publishedRef , data ) ;
681
+ if ( commitBatch ) {
682
+ await batch . commit ( ) ;
683
+ this . logAction ( 'translations.publish' , { metadata : { translationsId} } ) ;
684
+ }
685
+ }
686
+
638
687
/**
639
688
* Checks if a doc is currently "locked" for publishing.
640
689
*/
@@ -665,8 +714,6 @@ export class RootCMSClient {
665
714
options ?: LoadTranslationsOptions
666
715
) : Promise < TranslationsMap > {
667
716
const dbPath = `Projects/${ this . projectId } /TranslationsManager/published/Translations` ;
668
- const query : Query = this . db . collection ( dbPath ) ;
669
- const snapshot = await query . get ( ) ;
670
717
const translationsMap : TranslationsMap = { } ;
671
718
672
719
const addTranslations = ( hash : string , translations : Translation ) => {
@@ -676,6 +723,11 @@ export class RootCMSClient {
676
723
) ;
677
724
} ;
678
725
726
+ let query : Query = this . db . collection ( dbPath ) ;
727
+ if ( options ?. tags && options . tags . length > 0 ) {
728
+ query = query . where ( 'sys.tags' , 'array-contains-any' , options . tags ) ;
729
+ }
730
+ const snapshot = await query . get ( ) ;
679
731
snapshot . forEach ( ( doc ) => {
680
732
const data = doc . data ( ) ;
681
733
const strings = ( data . strings || { } ) as Record < string , Translation > ;
0 commit comments