public static function add($extension, $dictionary = null)
    {
        $extension = ExtensionManager::validate($extension);
        if ($dictionary === null) {
            $dictionary = $extension->getDictionary();
        }
        $dictionary = static::validate($dictionary);
        if (empty($dictionary)) {
            return true;
        }
        $transaction = Yii::$app->db->beginTransaction();
        try {
            foreach ($dictionary as $words) {
                $headword = $words[0];
                $headword = static::addHeadword($extension, $headword);
                if (!($headword instanceof \rhoone\models\Headword) || !$headword) {
                    throw new InvalidParamException("Failed to add headword.");
                }
                foreach ($words as $key => $synonyms) {
                    if (!$headword->setSynonyms($synonyms)) {
                        throw new InvalidParamException("Failed to add synonyms. It's headword is `" . $headword->word . "`.");
                    }
                }
            }
            $transaction->commit();
        } catch (\Exception $ex) {
            $transaction->rollBack();
            throw $ex;
        }
        return true;
    }