Skip to content

Commit 74a37ae

Browse files
authored
feat(firestore): add client language support for Firestore plugin on Android and iOS (#17830)
* feat(firestore): add client language support for Firestore plugin on Android and iOS * fix: remove redundant 'fire/' suffix from client language string on Android and iOS
1 parent 38fc083 commit 74a37ae

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static com.google.firebase.firestore.AggregateField.count;
99
import static com.google.firebase.firestore.AggregateField.sum;
1010

11+
import android.annotation.SuppressLint;
1112
import android.app.Activity;
1213
import android.util.Log;
1314
import androidx.annotation.NonNull;
@@ -33,6 +34,7 @@
3334
import com.google.firebase.firestore.Source;
3435
import com.google.firebase.firestore.Transaction;
3536
import com.google.firebase.firestore.WriteBatch;
37+
import com.google.firebase.firestore.remote.FirestoreChannel;
3638
import io.flutter.embedding.engine.plugins.FlutterPlugin;
3739
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
3840
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
@@ -129,9 +131,12 @@ private static void destroyCachedFirebaseFirestoreInstanceForKey(FirebaseFiresto
129131
}
130132
}
131133

134+
@SuppressLint("RestrictedApi")
132135
@Override
133136
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
134137
initInstance(binding.getBinaryMessenger());
138+
FirestoreChannel.setClientLanguage(
139+
"gl-dart/" + io.flutter.plugins.firebase.firestore.BuildConfig.LIBRARY_VERSION);
135140
}
136141

137142
@Override

packages/cloud_firestore/cloud_firestore/ios/cloud_firestore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Pod::Spec.new do |s|
2424
s.license = { :file => '../LICENSE' }
2525
s.authors = 'The Chromium Authors'
2626
s.source = { :path => '.' }
27-
s.source_files = 'cloud_firestore/Sources/cloud_firestore/**/*.{h,m}'
27+
s.source_files = 'cloud_firestore/Sources/cloud_firestore/**/*.{h,m,mm}'
2828
s.public_header_files = 'cloud_firestore/Sources/cloud_firestore/include/Public/**/*.h'
2929
s.private_header_files = 'cloud_firestore/Sources/cloud_firestore/include/Private/**/*.h'
3030

packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestorePlugin.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
NSString *const kFLTFirebaseFirestoreLoadBundleChannelName =
3434
@"plugins.flutter.io/firebase_firestore/loadBundle";
3535

36+
@interface FLTFirestoreClientLanguage : NSObject
37+
+ (void)setClientLanguage:(NSString *)language;
38+
@end
39+
3640
@interface FLTFirebaseFirestorePlugin ()
3741
@property(nonatomic, retain) NSMutableDictionary *transactions;
3842

@@ -122,6 +126,10 @@ - (instancetype)init:(NSObject<FlutterBinaryMessenger> *)messenger {
122126
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
123127
FLTFirebaseFirestorePlugin *instance =
124128
[[FLTFirebaseFirestorePlugin alloc] init:[registrar messenger]];
129+
#if TARGET_OS_IPHONE
130+
[FLTFirestoreClientLanguage
131+
setClientLanguage:[NSString stringWithFormat:@"gl-dart/%@", @LIBRARY_VERSION]];
132+
#endif
125133

126134
#if TARGET_OS_OSX
127135
// TODO(Salakar): Publish does not exist on MacOS version of FlutterPluginRegistrar.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2025 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import <Foundation/Foundation.h>
6+
#import <string>
7+
8+
namespace firebase {
9+
namespace firestore {
10+
namespace api {
11+
12+
class Firestore {
13+
public:
14+
static void SetClientLanguage(std::string language_token);
15+
};
16+
17+
} // namespace api
18+
} // namespace firestore
19+
} // namespace firebase
20+
21+
@interface FLTFirestoreClientLanguage : NSObject
22+
+ (void)setClientLanguage:(NSString *)language;
23+
@end
24+
25+
@implementation FLTFirestoreClientLanguage
26+
+ (void)setClientLanguage:(NSString *)language {
27+
if (language == nil) {
28+
return;
29+
}
30+
std::string token = std::string([language UTF8String]);
31+
firebase::firestore::api::Firestore::SetClientLanguage(token);
32+
}
33+
@end

0 commit comments

Comments
 (0)