-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add localized app name support on ios and android
Fixes #7
- Loading branch information
Showing
5 changed files
with
171 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import withAndroidLocalizedName from './vendors/expo-android-localized-app-name'; | ||
|
||
module.exports = ({ config }) => { | ||
return { | ||
...config, | ||
name: '巴士到站預報 - hkbus.app', | ||
slug: 'hkbusedemo-dev', // Replace with your app's slug | ||
version: '2.8.1', // Your app's version | ||
orientation: 'portrait', | ||
icon: './assets/icon.png', | ||
splash: { | ||
image: './assets/splash.png', | ||
resizeMode: "contain", | ||
backgroundColor: "#000000" | ||
}, | ||
updates: { | ||
fallbackToCacheTimeout: 0, | ||
url: 'https://u.expo.dev/d05aadae-7952-423d-bc30-31504dfbf8d2', | ||
requestHeaders: { | ||
'expo-channel-name': 'production' | ||
}, | ||
enabled: false | ||
}, | ||
plugins: [ | ||
[ | ||
'expo-tracking-transparency', | ||
{ | ||
userTrackingPermission: 'This identifier will be used to count the number of active users.' | ||
} | ||
], | ||
[ | ||
'expo-location', | ||
{ | ||
locationAlwaysAndWhenInUsePermission: 'Geolocation permission will be used to alert your arrival for the stop', | ||
locationWhenInUsePermission: 'Your location will be used to determine the nearby bus stops', | ||
locationAlwaysPermission: 'Geolocation permission will be used to alert your arrival for the stop', | ||
isAndroidBackgroundLocationEnabled: true | ||
} | ||
], | ||
[ | ||
'expo-notifications', | ||
{ | ||
icon: './assets/logo96.png', | ||
iosDisplayInForegroud: true | ||
} | ||
], | ||
[ | ||
'expo-build-properties', | ||
{ | ||
android: { | ||
targetSdkVersion: 34, | ||
minSdkVersion: 29 | ||
} | ||
} | ||
], | ||
withAndroidLocalizedName | ||
], | ||
ios: { | ||
supportsTablet: true, | ||
bundleIdentifier: 'app.hkbus', | ||
infoPlist: { | ||
CFBundleAllowMixedLocalizations: true, | ||
NSLocationAlwaysAndWhenInUseUsageDescription: 'Your location will be used to determine the nearby bus stops', | ||
NSLocationWhenInUseUsageDescription: 'Your location will be used to determine the nearby bus stops', | ||
NSUserTrackingUsageDescription: 'This identifier will be used to count the number of active users.', | ||
UIBackgroundModes: [ | ||
'location', | ||
'remote-notification' | ||
] | ||
}, | ||
appStoreUrl: 'https://apps.apple.com/hk/app/%E5%B7%B4%E5%A3%AB%E5%88%B0%E7%AB%99%E9%A0%90%E5%A0%B1-hkbus-app/id1612184906', | ||
associatedDomains: [ | ||
'applinks:hkbus.app' | ||
], | ||
buildNumber: '8' | ||
}, | ||
android: { | ||
adaptiveIcon: { | ||
foregroundImage: './assets/adaptive-icon.png', | ||
backgroundColor: '#000000' | ||
}, | ||
package: 'app.hkbus', | ||
versionCode: 21, | ||
intentFilters: [ | ||
{ | ||
action: 'VIEW', | ||
autoVerify: true, | ||
data: [ | ||
{ | ||
scheme: 'https', | ||
host: 'hkbus.app', | ||
pathPrefix: '/' | ||
} | ||
], | ||
category: [ | ||
'BROWSABLE', | ||
'DEFAULT' | ||
] | ||
} | ||
] | ||
}, | ||
web: { | ||
favicon: './assets/favicon.png' | ||
}, | ||
extra: { | ||
eas: { | ||
projectId: 'd138ee5b-fb89-4552-ab28-d574884df2c6' | ||
} | ||
}, | ||
runtimeVersion: { | ||
policy: 'appVersion' | ||
}, | ||
locales: { | ||
en: './locales/en.json', | ||
'zh-Hant': './locales/zh-Hant.json' | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"CFBundleDisplayName": "hkbus.app", | ||
"app_name": "hkbus.app" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"CFBundleDisplayName": "巴士到站預報", | ||
"app_name": "巴士到站預報" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Source: https://github.com/mmomtchev/expo-android-localized-app-name/pull/3 | ||
// `expo-android-localized-app-name` at the moment does not support `zh-Hant` locale and that repo is not maintained anymore | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { withStringsXml, AndroidConfig } = require('@expo/config-plugins'); | ||
const xml2js = require('xml2js'); | ||
const builder = new xml2js.Builder({ headless: true }); | ||
|
||
function withAndroidLocalizedName(config) { | ||
return withStringsXml(config, | ||
async config => { | ||
const projectRoot = config.modRequest.projectRoot; | ||
const resPath = await AndroidConfig.Paths.getResourceFolderAsync(projectRoot); | ||
for (const locale of Object.keys(config.locales ?? {})) { | ||
const json = await fs.promises.readFile(config.locales[locale]); | ||
const strings = JSON.parse(json); | ||
const resources = []; | ||
for (const key of Object.keys(strings)) { | ||
// Skip values that are not marked for translation or simply do not exist | ||
// because gradle does not like them | ||
const untranslated = config.modResults.resources.string?.find(item => | ||
item.$.name === key && item.$.translatable !== false); | ||
if (untranslated) | ||
resources.push({ string: { $: { name: key }, _: strings[key] } }); | ||
} | ||
if (resources.length) { | ||
let finalLocale = locale; | ||
if (finalLocale.includes("-")) { | ||
finalLocale = `b+${finalLocale.replaceAll("-", "+")}`; | ||
} | ||
await fs.promises.mkdir(path.resolve(resPath, `values-${finalLocale}`), { | ||
recursive: true, | ||
}); | ||
await fs.promises.writeFile( | ||
path.resolve(resPath, `values-${finalLocale}`, 'strings.xml'), | ||
builder.buildObject({ resources }) | ||
); | ||
} | ||
} | ||
return config; | ||
}, | ||
); | ||
}; | ||
|
||
module.exports = withAndroidLocalizedName; |