Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) Wait for slugify to show up before returning slug #4049

Merged
merged 3 commits into from
Apr 4, 2018
Merged
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
25 changes: 22 additions & 3 deletions lib/api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ let slugify;
async function lazyLoadSlugify() {
let mod;
// getting the shops base language
const lang = getShopLang();
let lang;
if (Meteor.isServer) {
lang = getPrimaryShopLang();
} else {
lang = getShopLang();
}

// if slugify has been loaded but the language has changed
// to be a non latin based language then load transliteration
if (slugify && slugify.name === "replace" && latinLangs.indexOf(lang) === -1) {
Expand Down Expand Up @@ -117,6 +123,19 @@ export function getShopLang() {
return shop ? shop.language : "";
}

/**
* @name getPrimaryShopLang
* @method
* @memberof Helpers
* @return {String} returns primary shop language
*/
export function getPrimaryShopLang() {
const shopId = getPrimaryShopId();
const shop = Shops.findOne({ _id: shopId });
return shop ? shop.language : "";
}


/**
* @name getShopPrefix
* @method
Expand Down Expand Up @@ -199,8 +218,8 @@ export function getCurrentTag() {
*/
export function getSlug(slugString) {
let slug;
Promise.resolve(lazyLoadSlugify());
if (slugString && slugify) {
Promise.await(lazyLoadSlugify());
if (slugString) {
slug = slugify(slugString.toLowerCase());
} else {
slug = "";
Expand Down