Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { withAndroidLanguages } from './android';
import { withIosLanguages } from './ios';

const withReactNativeLocalizationSettings: ConfigPlugin<{
defaultLanguage?: string;
languages?: string[];
}> = (config, { languages = [] } = {}) => {
}> = (config, { defaultLanguage, languages = [] } = {}) => {
config = withAndroidLanguages(config, { languages });
config = withIosLanguages(config, { languages });
config = withIosLanguages(config, { defaultLanguage, languages });

return config;
};
Expand Down
15 changes: 9 additions & 6 deletions plugin/src/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
withXcodeProject,
} from '@expo/config-plugins';

const generateLocalizableContent = (languages: string[]) => `{
"sourceLanguage" : "Base",
const generateLocalizableContent = (
languages: string[],
defaultLanguage?: string
) => `{
"sourceLanguage" : "${defaultLanguage || languages[0]}",
"strings" : {
"react-native-localization-settings" : {
"extractionState" : "manual",
"localizations" : {
"base" : {"stringUnit" : {"state" : "translated","value" : ""}},
${languages
.map(
(lang) =>
Expand All @@ -24,22 +26,23 @@
}`;

export const withIosLanguages: ConfigPlugin<{
defaultLanguage?: string;
languages?: string[];
}> = (config, { languages = [] } = {}) => {
}> = (config, { defaultLanguage, languages = [] } = {}) => {
config = withXcodeProject(config, (config) => {

Check warning on line 32 in plugin/src/ios.ts

View workflow job for this annotation

GitHub Actions / lint

'config' is already declared in the upper scope on line 31 column 7
const project = config.modResults;
const projectObject =
project.pbxProjectSection()[project.getFirstProject().uuid];
if (projectObject) {
// Add known regions to the project
projectObject.knownRegions = ['Base', ...languages];
projectObject.knownRegions = languages;

// Write the Localizable.xcstrings file
IOSConfig.XcodeProjectFile.createBuildSourceFile({
project,
nativeProjectRoot: config.modRequest.platformProjectRoot,
filePath: 'Localizable.xcstrings',
fileContents: generateLocalizableContent(languages),
fileContents: generateLocalizableContent(languages, defaultLanguage),
overwrite: true,
});
}
Expand Down
Loading